Skip to content

Commit 36e855c

Browse files
authored
Merge pull request #142 from sx-aurora-dev/feature/merge-upstream-20220118
Feature/merge upstream 20220118
2 parents b9f31da + 09203a9 commit 36e855c

File tree

314 files changed

+12380
-4333
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

314 files changed

+12380
-4333
lines changed

clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ namespace misc {
1818

1919
void UnconventionalAssignOperatorCheck::registerMatchers(
2020
ast_matchers::MatchFinder *Finder) {
21-
const auto HasGoodReturnType = cxxMethodDecl(returns(lValueReferenceType(
22-
pointee(unless(isConstQualified()),
23-
anyOf(autoType(), hasDeclaration(equalsBoundNode("class")))))));
21+
const auto HasGoodReturnType =
22+
cxxMethodDecl(returns(hasCanonicalType(lValueReferenceType(pointee(
23+
unless(isConstQualified()),
24+
anyOf(autoType(), hasDeclaration(equalsBoundNode("class"))))))));
2425

25-
const auto IsSelf = qualType(
26+
const auto IsSelf = qualType(hasCanonicalType(
2627
anyOf(hasDeclaration(equalsBoundNode("class")),
27-
referenceType(pointee(hasDeclaration(equalsBoundNode("class"))))));
28+
referenceType(pointee(hasDeclaration(equalsBoundNode("class")))))));
2829
const auto IsAssign =
2930
cxxMethodDecl(unless(anyOf(isDeleted(), isPrivate(), isImplicit())),
3031
hasName("operator="), ofClass(recordDecl().bind("class")))
@@ -37,9 +38,9 @@ void UnconventionalAssignOperatorCheck::registerMatchers(
3738
cxxMethodDecl(IsAssign, unless(HasGoodReturnType)).bind("ReturnType"),
3839
this);
3940

40-
const auto BadSelf = referenceType(
41+
const auto BadSelf = qualType(hasCanonicalType(referenceType(
4142
anyOf(lValueReferenceType(pointee(unless(isConstQualified()))),
42-
rValueReferenceType(pointee(isConstQualified()))));
43+
rValueReferenceType(pointee(isConstQualified()))))));
4344

4445
Finder->addMatcher(
4546
cxxMethodDecl(IsSelfAssign,

clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void RedundantDeclarationCheck::registerMatchers(MatchFinder *Finder) {
3737
functionDecl(unless(anyOf(
3838
isDefinition(), isDefaulted(),
3939
doesDeclarationForceExternallyVisibleDefinition(),
40-
hasParent(friendDecl()))))))
40+
hasAncestor(friendDecl()))))))
4141
.bind("Decl"),
4242
this);
4343
}

clang-tools-extra/clangd/Selection.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,13 +794,16 @@ class SelectionVisitor : public RecursiveASTVisitor<SelectionVisitor> {
794794
}
795795

796796
// Pushes a node onto the ancestor stack. Pairs with pop().
797+
// Performs early hit detection for some nodes (on the earlySourceRange).
797798
void push(DynTypedNode Node) {
799+
SourceRange Early = earlySourceRange(Node);
798800
dlog("{1}push: {0}", printNodeToString(Node, PrintPolicy), indent());
799801
Nodes.emplace_back();
800802
Nodes.back().ASTNode = std::move(Node);
801803
Nodes.back().Parent = Stack.top();
802804
Nodes.back().Selected = NoTokens;
803805
Stack.push(&Nodes.back());
806+
claimRange(Early, Nodes.back().Selected);
804807
}
805808

806809
// Pops a node off the ancestor stack, and finalizes it. Pairs with push().
@@ -822,6 +825,26 @@ class SelectionVisitor : public RecursiveASTVisitor<SelectionVisitor> {
822825
Stack.pop();
823826
}
824827

828+
// Returns the range of tokens that this node will claim directly, and
829+
// is not available to the node's children.
830+
// Usually empty, but sometimes children cover tokens but shouldn't own them.
831+
SourceRange earlySourceRange(const DynTypedNode &N) {
832+
if (const Decl *D = N.get<Decl>()) {
833+
// We want the name in the var-decl to be claimed by the decl itself and
834+
// not by any children. Ususally, we don't need this, because source
835+
// ranges of children are not overlapped with their parent's.
836+
// An exception is lambda captured var decl, where AutoTypeLoc is
837+
// overlapped with the name loc.
838+
// auto fun = [bar = foo]() { ... }
839+
// ~~~~~~~~~ VarDecl
840+
// ~~~ |- AutoTypeLoc
841+
if (const auto *DD = llvm::dyn_cast<VarDecl>(D))
842+
return DD->getLocation();
843+
}
844+
845+
return SourceRange();
846+
}
847+
825848
// Claim tokens for N, after processing its children.
826849
// By default this claims all unclaimed tokens in getSourceRange().
827850
// We override this if we want to claim fewer tokens (e.g. there are gaps).

clang-tools-extra/clangd/refactor/Rename.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,8 @@ llvm::DenseSet<const NamedDecl *> locateDeclAt(ParsedAST &AST,
164164
// to be good candidates for modification.
165165
bool isExcluded(const NamedDecl &RenameDecl) {
166166
const auto &SM = RenameDecl.getASTContext().getSourceManager();
167-
if (SM.isInSystemHeader(RenameDecl.getLocation()))
168-
return true;
169-
if (isProtoFile(RenameDecl.getLocation(), SM))
170-
return true;
171-
// FIXME: Remove this std symbol list, as they should be covered by the
172-
// above isInSystemHeader check.
173-
static const auto *StdSymbols = new llvm::DenseSet<llvm::StringRef>({
174-
#define SYMBOL(Name, NameSpace, Header) {#NameSpace #Name},
175-
#include "StdSymbolMap.inc"
176-
#undef SYMBOL
177-
});
178-
return StdSymbols->count(printQualifiedName(RenameDecl));
167+
return SM.isInSystemHeader(RenameDecl.getLocation()) ||
168+
isProtoFile(RenameDecl.getLocation(), SM);
179169
}
180170

181171
enum class ReasonToReject {

clang-tools-extra/clangd/unittests/RenameTests.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -880,21 +880,6 @@ TEST(RenameTest, Renameable) {
880880
void f(X x) {x+^+;})cpp",
881881
"no symbol", HeaderFile},
882882

883-
{R"cpp(// disallow rename on excluded symbols (e.g. std symbols)
884-
namespace std {
885-
class str^ing {};
886-
}
887-
)cpp",
888-
"not a supported kind", !HeaderFile},
889-
{R"cpp(// disallow rename on excluded symbols (e.g. std symbols)
890-
namespace std {
891-
inline namespace __u {
892-
class str^ing {};
893-
}
894-
}
895-
)cpp",
896-
"not a supported kind", !HeaderFile},
897-
898883
{R"cpp(// disallow rename on non-normal identifiers.
899884
@interface Foo {}
900885
-(int) fo^o:(int)x; // Token is an identifier, but declaration name isn't a simple identifier.
@@ -1199,26 +1184,37 @@ TEST(RenameTest, MainFileReferencesOnly) {
11991184
}
12001185

12011186
TEST(RenameTest, NoRenameOnSymbolsFromSystemHeaders) {
1202-
// filter out references not from main file.
12031187
llvm::StringRef Test =
12041188
R"cpp(
1189+
#include <cstdlib>
12051190
#include <system>
1191+
12061192
SystemSym^bol abc;
1193+
1194+
void foo() { at^oi("9000"); }
12071195
)cpp";
12081196

12091197
Annotations Code(Test);
12101198
auto TU = TestTU::withCode(Code.code());
12111199
TU.AdditionalFiles["system"] = R"cpp(
12121200
class SystemSymbol {};
12131201
)cpp";
1202+
TU.AdditionalFiles["cstdlib"] = R"cpp(
1203+
int atoi(const char *str);
1204+
)cpp";
12141205
TU.ExtraArgs = {"-isystem", testRoot()};
12151206
auto AST = TU.build();
12161207
llvm::StringRef NewName = "abcde";
12171208

1218-
auto Results = rename({Code.point(), NewName, AST, testPath(TU.Filename)});
1219-
EXPECT_FALSE(Results) << "expected rename returned an error: " << Code.code();
1220-
auto ActualMessage = llvm::toString(Results.takeError());
1221-
EXPECT_THAT(ActualMessage, testing::HasSubstr("not a supported kind"));
1209+
// Clangd will not allow renaming symbols from the system headers for
1210+
// correctness.
1211+
for (auto &Point : Code.points()) {
1212+
auto Results = rename({Point, NewName, AST, testPath(TU.Filename)});
1213+
EXPECT_FALSE(Results) << "expected rename returned an error: "
1214+
<< Code.code();
1215+
auto ActualMessage = llvm::toString(Results.takeError());
1216+
EXPECT_THAT(ActualMessage, testing::HasSubstr("not a supported kind"));
1217+
}
12221218
}
12231219

12241220
TEST(RenameTest, ProtobufSymbolIsExcluded) {

clang-tools-extra/clangd/unittests/SelectionTests.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,13 @@ TEST(SelectionTest, CommonAncestor) {
516516
enum Bar : [[Fo^o]];
517517
)cpp",
518518
"TypedefTypeLoc"},
519+
520+
// lambda captured var-decl
521+
{R"cpp(
522+
void test(int bar) {
523+
auto l = [^[[foo = bar]]] { };
524+
})cpp",
525+
"VarDecl"},
519526
};
520527

521528
for (const Case &C : Cases) {

clang-tools-extra/docs/clang-tidy/checks/misc-unconventional-assign-operator.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Finds declarations of assign operators with the wrong return and/or argument
88
types and definitions with good return type but wrong ``return`` statements.
99

1010
* The return type must be ``Class&``.
11-
* Works with move-assign and assign by value.
11+
* The assignment may be from the class type by value, const lvalue
12+
reference, non-const rvalue reference, or from a completely different
13+
type (e.g. ``int``).
1214
* Private and deleted operators are ignored.
1315
* The operator must always return ``*this``.

clang-tools-extra/test/clang-tidy/checkers/misc-unconventional-assign-operator.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,39 @@ struct AssignmentCallAtReturn {
127127
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: operator=() should always return '*this'
128128
}
129129
};
130+
131+
// Check that no false positives are issued when using type aliases.
132+
struct TypeAlias {
133+
using Alias = TypeAlias;
134+
// This is correct and should not produce any warnings:
135+
Alias &operator=(const Alias &) { return *this; }
136+
137+
using AliasRef = Alias &;
138+
// So is this (assignments from other types are fine):
139+
AliasRef operator=(int) { return *this; }
140+
};
141+
142+
// Same check as above with typedef instead of using
143+
struct TypeAliasTypedef {
144+
typedef TypeAliasTypedef Alias;
145+
Alias &operator=(const Alias &) { return *this; }
146+
147+
typedef Alias &AliasRef;
148+
AliasRef operator=(int) { return *this; }
149+
};
150+
151+
// Same check as above for a template class
152+
template <typename T>
153+
struct TemplateTypeAlias {
154+
using Alias1 = TemplateTypeAlias &;
155+
using Alias2 = TemplateTypeAlias const &;
156+
Alias1 operator=(Alias2) { return *this; }
157+
158+
template <typename U>
159+
using Alias3 = TemplateTypeAlias<U>;
160+
Alias3<T> &operator=(int) { return *this; }
161+
162+
// Using a different type parameter in the return type should give a warning
163+
Alias3<TypeAlias::Alias> &operator=(double) { return *this; }
164+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should return 'TemplateTypeAlias&' [misc-unconventional-assign-operator]
165+
};

clang-tools-extra/test/clang-tidy/checkers/readability-redundant-declaration.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,32 @@ struct Friendly {
7070

7171
void enemy();
7272

73+
template <typename>
74+
struct TemplateFriendly {
75+
template <typename T>
76+
friend void generic_friend();
77+
};
78+
79+
template <typename T>
80+
void generic_friend() {}
81+
82+
TemplateFriendly<int> template_friendly;
83+
84+
template <typename>
85+
struct TemplateFriendly2 {
86+
template <typename T>
87+
friend void generic_friend2() {}
88+
};
89+
90+
template <typename T>
91+
void generic_friend2();
92+
93+
void generic_friend_caller() {
94+
TemplateFriendly2<int> f;
95+
generic_friend2<int>();
96+
}
97+
98+
7399
namespace macros {
74100
#define DECLARE(x) extern int x
75101
#define DEFINE(x) extern int x; int x = 42

clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ class Environment {
116116
/// in the environment.
117117
StorageLocation *getThisPointeeStorageLocation() const;
118118

119-
/// Creates a value appropriate for `Type`, assigns it to `Loc`, and returns
120-
/// it, if `Type` is supported, otherwise return null. If `Type` is a pointer
121-
/// or reference type, creates all the necessary storage locations and values
122-
/// for indirections until it finds a non-pointer/non-reference type.
119+
/// Creates a value appropriate for `Type`, if `Type` is supported, otherwise
120+
/// return null. If `Type` is a pointer or reference type, creates all the
121+
/// necessary storage locations and values for indirections until it finds a
122+
/// non-pointer/non-reference type.
123123
///
124124
/// Requirements:
125125
///
126126
/// `Type` must not be null.
127-
Value *initValueInStorageLocation(const StorageLocation &Loc, QualType Type);
127+
Value *createValue(QualType Type);
128128

129129
/// Assigns `Val` as the value of `Loc` in the environment.
130130
void setValue(const StorageLocation &Loc, Value &Val);
@@ -150,8 +150,8 @@ class Environment {
150150
Value &takeOwnership(std::unique_ptr<Value> Val);
151151

152152
private:
153-
/// Returns the value assigned to `Loc` in the environment or null if `Type`
154-
/// isn't supported.
153+
/// Creates a value appropriate for `Type`, if `Type` is supported, otherwise
154+
/// return null.
155155
///
156156
/// Recursively initializes storage locations and values until it sees a
157157
/// self-referential pointer or reference type. `Visited` is used to track
@@ -161,9 +161,8 @@ class Environment {
161161
/// Requirements:
162162
///
163163
/// `Type` must not be null.
164-
Value *initValueInStorageLocationUnlessSelfReferential(
165-
const StorageLocation &Loc, QualType Type,
166-
llvm::DenseSet<QualType> &Visited);
164+
Value *createValueUnlessSelfReferential(QualType Type,
165+
llvm::DenseSet<QualType> &Visited);
167166

168167
StorageLocation &skip(StorageLocation &Loc, SkipPast SP) const;
169168
const StorageLocation &skip(const StorageLocation &Loc, SkipPast SP) const;

0 commit comments

Comments
 (0)