Skip to content

Commit ad4d221

Browse files
committed
Merge commit '81b1d3da094c54ffd75e05c8d4683792edf17f4c' into feature/merge-upstream-20210212
2 parents fe9e55d + 81b1d3d commit ad4d221

File tree

2,525 files changed

+78962
-41423
lines changed

Some content is hidden

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

2,525 files changed

+78962
-41423
lines changed

clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,10 +712,11 @@ StringRef LoopConvertCheck::getContainerString(ASTContext *Context,
712712
if (isa<CXXThisExpr>(ContainerExpr)) {
713713
ContainerString = "this";
714714
} else {
715-
// For CXXOperatorCallExpr (e.g. vector_ptr->size()), its first argument is
716-
// the class object (vector_ptr) we are targeting.
715+
// For CXXOperatorCallExpr such as vector_ptr->size() we want the class
716+
// object vector_ptr, but for vector[2] we need the whole expression.
717717
if (const auto* E = dyn_cast<CXXOperatorCallExpr>(ContainerExpr))
718-
ContainerExpr = E->getArg(0);
718+
if (E->getOperator() != OO_Subscript)
719+
ContainerExpr = E->getArg(0);
719720
ContainerString =
720721
getStringFromRange(Context->getSourceManager(), Context->getLangOpts(),
721722
ContainerExpr->getSourceRange());

clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,28 @@ StatementMatcher makeCastSequenceMatcher() {
4141
unless(hasImplicitDestinationType(qualType(substTemplateTypeParmType()))),
4242
unless(hasSourceExpression(hasType(sugaredNullptrType()))));
4343

44+
auto IsOrHasDescendant = [](auto InnerMatcher) {
45+
return anyOf(InnerMatcher, hasDescendant(InnerMatcher));
46+
};
47+
4448
return traverse(
4549
TK_AsIs,
46-
castExpr(anyOf(ImplicitCastToNull,
47-
explicitCastExpr(hasDescendant(ImplicitCastToNull))),
48-
unless(hasAncestor(explicitCastExpr())))
49-
.bind(CastSequence));
50+
anyOf(castExpr(anyOf(ImplicitCastToNull,
51+
explicitCastExpr(hasDescendant(ImplicitCastToNull))),
52+
unless(hasAncestor(explicitCastExpr())),
53+
unless(hasAncestor(cxxRewrittenBinaryOperator())))
54+
.bind(CastSequence),
55+
cxxRewrittenBinaryOperator(
56+
// Match rewritten operators, but verify (in the check method)
57+
// that if an implicit cast is found, it is not from another
58+
// nested rewritten operator.
59+
expr().bind("matchBinopOperands"),
60+
hasEitherOperand(IsOrHasDescendant(
61+
implicitCastExpr(
62+
ImplicitCastToNull,
63+
hasAncestor(cxxRewrittenBinaryOperator().bind(
64+
"checkBinopOperands")))
65+
.bind(CastSequence))))));
5066
}
5167

5268
bool isReplaceableRange(SourceLocation StartLoc, SourceLocation EndLoc,
@@ -480,6 +496,11 @@ void UseNullptrCheck::check(const MatchFinder::MatchResult &Result) {
480496
const auto *NullCast = Result.Nodes.getNodeAs<CastExpr>(CastSequence);
481497
assert(NullCast && "Bad Callback. No node provided");
482498

499+
if (Result.Nodes.getNodeAs<CXXRewrittenBinaryOperator>(
500+
"matchBinopOperands") !=
501+
Result.Nodes.getNodeAs<CXXRewrittenBinaryOperator>("checkBinopOperands"))
502+
return;
503+
483504
// Given an implicit null-ptr cast or an explicit cast with an implicit
484505
// null-to-pointer cast within use CastSequenceVisitor to identify sequences
485506
// of explicit casts that can be converted into 'nullptr'.

clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ static bool isTypedefTypeMatching(const TypedefType *const Typedef,
228228
/// Get the unqualified, dereferenced type of an argument.
229229
///
230230
/// \param CE call expression
231-
/// \param idx argument index
231+
/// \param Idx argument index
232232
///
233233
/// \returns type of the argument
234234
static const Type *argumentType(const CallExpr *const CE, const size_t Idx) {

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

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ AST_MATCHER(Expr, usedInBooleanContext) {
8383
});
8484
return Result;
8585
}
86+
AST_MATCHER(CXXConstructExpr, isDefaultConstruction) {
87+
return Node.getConstructor()->isDefaultConstructor();
88+
}
8689
} // namespace ast_matchers
8790
namespace tidy {
8891
namespace readability {
@@ -116,24 +119,16 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
116119
const auto ValidContainer = qualType(
117120
anyOf(ValidContainerNonTemplateType, ValidContainerTemplateType));
118121

119-
const auto WrongUse = traverse(
120-
TK_AsIs,
121-
anyOf(
122-
hasParent(binaryOperator(isComparisonOperator(),
123-
hasEitherOperand(ignoringImpCasts(
124-
anyOf(integerLiteral(equals(1)),
125-
integerLiteral(equals(0))))))
126-
.bind("SizeBinaryOp")),
127-
hasParent(implicitCastExpr(
128-
hasImplicitDestinationType(booleanType()),
129-
anyOf(hasParent(
130-
unaryOperator(hasOperatorName("!")).bind("NegOnSize")),
131-
anything()))),
132-
usedInBooleanContext()));
122+
const auto WrongUse =
123+
anyOf(hasParent(binaryOperator(
124+
isComparisonOperator(),
125+
hasEitherOperand(anyOf(integerLiteral(equals(1)),
126+
integerLiteral(equals(0)))))
127+
.bind("SizeBinaryOp")),
128+
usedInBooleanContext());
133129

134130
Finder->addMatcher(
135-
cxxMemberCallExpr(unless(isInTemplateInstantiation()),
136-
on(expr(anyOf(hasType(ValidContainer),
131+
cxxMemberCallExpr(on(expr(anyOf(hasType(ValidContainer),
137132
hasType(pointsTo(ValidContainer)),
138133
hasType(references(ValidContainer))))
139134
.bind("MemberCallObject")),
@@ -157,18 +152,9 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
157152
.bind("SizeCallExpr"),
158153
this);
159154

160-
// Empty constructor matcher.
161-
const auto DefaultConstructor = cxxConstructExpr(
162-
hasDeclaration(cxxConstructorDecl(isDefaultConstructor())));
163155
// Comparison to empty string or empty constructor.
164156
const auto WrongComparend = anyOf(
165-
ignoringImpCasts(stringLiteral(hasSize(0))),
166-
ignoringImpCasts(cxxBindTemporaryExpr(has(DefaultConstructor))),
167-
ignoringImplicit(DefaultConstructor),
168-
cxxConstructExpr(hasDeclaration(cxxConstructorDecl(isCopyConstructor())),
169-
has(expr(ignoringImpCasts(DefaultConstructor)))),
170-
cxxConstructExpr(hasDeclaration(cxxConstructorDecl(isMoveConstructor())),
171-
has(expr(ignoringImpCasts(DefaultConstructor)))),
157+
stringLiteral(hasSize(0)), cxxConstructExpr(isDefaultConstruction()),
172158
cxxUnresolvedConstructExpr(argumentCountIs(0)));
173159
// Match the object being compared.
174160
const auto STLArg =
@@ -178,12 +164,11 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
178164
expr(hasType(pointsTo(ValidContainer))).bind("Pointee"))),
179165
expr(hasType(ValidContainer)).bind("STLObject"));
180166
Finder->addMatcher(
181-
binaryOperation(unless(isInTemplateInstantiation()),
182-
hasAnyOperatorName("==", "!="),
183-
hasOperands(ignoringParenImpCasts(WrongComparend),
184-
ignoringParenImpCasts(STLArg)),
185-
unless(hasAncestor(cxxMethodDecl(
186-
ofClass(equalsBoundNode("container"))))))
167+
binaryOperation(hasAnyOperatorName("==", "!="),
168+
hasOperands(WrongComparend,
169+
STLArg),
170+
unless(hasAncestor(cxxMethodDecl(
171+
ofClass(equalsBoundNode("container"))))))
187172
.bind("BinCmp"),
188173
this);
189174
}

clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class ContainerSizeEmptyCheck : public ClangTidyCheck {
3333
}
3434
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
3535
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
36+
llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
37+
return TK_IgnoreUnlessSpelledInSource;
38+
}
3639
};
3740

3841
} // namespace readability

clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ void TransformerClangTidyCheck::check(
104104
Diag << FixItHint::CreateReplacement(T.Range, T.Replacement);
105105
break;
106106
case transformer::EditKind::AddInclude:
107-
Diag << Inserter.createMainFileIncludeInsertion(T.Replacement);
107+
Diag << Inserter.createIncludeInsertion(
108+
Result.SourceManager->getFileID(T.Range.getBegin()), T.Replacement);
108109
break;
109110
}
110111
}

clang-tools-extra/clangd/AST.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,52 @@ std::string printNamespaceScope(const DeclContext &DC) {
283283
return "";
284284
}
285285

286+
static llvm::StringRef
287+
getNameOrErrForObjCInterface(const ObjCInterfaceDecl *ID) {
288+
return ID ? ID->getName() : "<<error-type>>";
289+
}
290+
291+
std::string printObjCMethod(const ObjCMethodDecl &Method) {
292+
std::string Name;
293+
llvm::raw_string_ostream OS(Name);
294+
295+
OS << (Method.isInstanceMethod() ? '-' : '+') << '[';
296+
297+
// Should always be true.
298+
if (const ObjCContainerDecl *C =
299+
dyn_cast<ObjCContainerDecl>(Method.getDeclContext()))
300+
OS << printObjCContainer(*C);
301+
302+
Method.getSelector().print(OS << ' ');
303+
if (Method.isVariadic())
304+
OS << ", ...";
305+
306+
OS << ']';
307+
OS.flush();
308+
return Name;
309+
}
310+
311+
std::string printObjCContainer(const ObjCContainerDecl &C) {
312+
if (const ObjCCategoryDecl *Category = dyn_cast<ObjCCategoryDecl>(&C)) {
313+
std::string Name;
314+
llvm::raw_string_ostream OS(Name);
315+
const ObjCInterfaceDecl *Class = Category->getClassInterface();
316+
OS << getNameOrErrForObjCInterface(Class) << '(' << Category->getName()
317+
<< ')';
318+
OS.flush();
319+
return Name;
320+
}
321+
if (const ObjCCategoryImplDecl *CID = dyn_cast<ObjCCategoryImplDecl>(&C)) {
322+
std::string Name;
323+
llvm::raw_string_ostream OS(Name);
324+
const ObjCInterfaceDecl *Class = CID->getClassInterface();
325+
OS << getNameOrErrForObjCInterface(Class) << '(' << CID->getName() << ')';
326+
OS.flush();
327+
return Name;
328+
}
329+
return C.getNameAsString();
330+
}
331+
286332
SymbolID getSymbolID(const Decl *D) {
287333
llvm::SmallString<128> USR;
288334
if (index::generateUSRForDecl(D, USR))

clang-tools-extra/clangd/AST.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "index/SymbolID.h"
1717
#include "clang/AST/Decl.h"
18+
#include "clang/AST/DeclObjC.h"
1819
#include "clang/AST/NestedNameSpecifier.h"
1920
#include "clang/Basic/SourceLocation.h"
2021
#include "clang/Lex/MacroInfo.h"
@@ -64,6 +65,14 @@ std::string printName(const ASTContext &Ctx, const NamedDecl &ND);
6465
/// string if decl is not a template specialization.
6566
std::string printTemplateSpecializationArgs(const NamedDecl &ND);
6667

68+
/// Print the Objective-C method name, including the full container name, e.g.
69+
/// `-[MyClass(Category) method:]`
70+
std::string printObjCMethod(const ObjCMethodDecl &Method);
71+
72+
/// Print the Objective-C container name including categories, e.g. `MyClass`,
73+
// `MyClass()`, `MyClass(Category)`, and `MyProtocol`.
74+
std::string printObjCContainer(const ObjCContainerDecl &C);
75+
6776
/// Gets the symbol ID for a declaration. Returned SymbolID might be null.
6877
SymbolID getSymbolID(const Decl *D);
6978

0 commit comments

Comments
 (0)