Skip to content

Commit 17fcfd9

Browse files
authored
LLVM and SPIRV-LLVM-Translator pulldown (WW35)
LLVM: llvm/llvm-project@3d1b000 SPIRV-LLVM-Translator: KhronosGroup/SPIRV-LLVM-Translator@0bcb157
2 parents c49303d + 024bd73 commit 17fcfd9

File tree

3,346 files changed

+197908
-73122
lines changed

Some content is hidden

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

3,346 files changed

+197908
-73122
lines changed

clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,18 @@ AST_POLYMORPHIC_MATCHER(
4747
if (PrefixPosition == StringRef::npos)
4848
return false;
4949
Path = Path.drop_front(PrefixPosition + AbslPrefix.size());
50-
static const char *AbseilLibraries[] = {
51-
"algorithm", "base", "container", "debugging", "flags",
52-
"hash", "iterator", "memory", "meta", "numeric",
53-
"random", "strings", "synchronization", "time", "types",
54-
"utility"};
55-
return std::any_of(
56-
std::begin(AbseilLibraries), std::end(AbseilLibraries),
57-
[&](const char *Library) { return Path.startswith(Library); });
50+
static const char *AbseilLibraries[] = {"algorithm", "base",
51+
"container", "debugging",
52+
"flags", "hash",
53+
"iterator", "memory",
54+
"meta", "numeric",
55+
"random", "status",
56+
"strings", "synchronization",
57+
"time", "types",
58+
"utility"};
59+
return llvm::any_of(AbseilLibraries, [&](const char *Library) {
60+
return Path.startswith(Library);
61+
});
5862
}
5963

6064
} // namespace ast_matchers

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

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ static bool hasAnyNestedLocalQualifiers(QualType Type) {
261261
}
262262

263263
SourceRange UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
264-
const FunctionDecl &F, const ASTContext &Ctx, const SourceManager &SM,
265-
const LangOptions &LangOpts) {
264+
const FunctionDecl &F, const TypeLoc &ReturnLoc, const ASTContext &Ctx,
265+
const SourceManager &SM, const LangOptions &LangOpts) {
266266

267267
// We start with the range of the return type and expand to neighboring
268268
// qualifiers (const, volatile and restrict).
@@ -274,6 +274,35 @@ SourceRange UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
274274
return {};
275275
}
276276

277+
// If the return type is a constrained 'auto' or 'decltype(auto)', we need to
278+
// include the tokens after the concept. Unfortunately, the source range of an
279+
// AutoTypeLoc, if it is constrained, does not include the 'auto' or
280+
// 'decltype(auto)'. If the return type is a plain 'decltype(...)', the
281+
// source range only contains the first 'decltype' token.
282+
auto ATL = ReturnLoc.getAs<AutoTypeLoc>();
283+
if ((ATL && (ATL.isConstrained() ||
284+
ATL.getAutoKeyword() == AutoTypeKeyword::DecltypeAuto)) ||
285+
ReturnLoc.getAs<DecltypeTypeLoc>()) {
286+
SourceLocation End =
287+
expandIfMacroId(ReturnLoc.getSourceRange().getEnd(), SM);
288+
SourceLocation BeginNameF = expandIfMacroId(F.getLocation(), SM);
289+
290+
// Extend the ReturnTypeRange until the last token before the function
291+
// name.
292+
std::pair<FileID, unsigned> Loc = SM.getDecomposedLoc(End);
293+
StringRef File = SM.getBufferData(Loc.first);
294+
const char *TokenBegin = File.data() + Loc.second;
295+
Lexer Lexer(SM.getLocForStartOfFile(Loc.first), LangOpts, File.begin(),
296+
TokenBegin, File.end());
297+
Token T;
298+
SourceLocation LastTLoc = End;
299+
while (!Lexer.LexFromRawLexer(T) &&
300+
SM.isBeforeInTranslationUnit(T.getLocation(), BeginNameF)) {
301+
LastTLoc = T.getLocation();
302+
}
303+
ReturnTypeRange.setEnd(LastTLoc);
304+
}
305+
277306
// If the return type has no local qualifiers, it's source range is accurate.
278307
if (!hasAnyNestedLocalQualifiers(F.getReturnType()))
279308
return ReturnTypeRange;
@@ -317,7 +346,7 @@ SourceRange UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
317346
return ReturnTypeRange;
318347
}
319348

320-
bool UseTrailingReturnTypeCheck::keepSpecifiers(
349+
void UseTrailingReturnTypeCheck::keepSpecifiers(
321350
std::string &ReturnType, std::string &Auto, SourceRange ReturnTypeCVRange,
322351
const FunctionDecl &F, const FriendDecl *Fr, const ASTContext &Ctx,
323352
const SourceManager &SM, const LangOptions &LangOpts) {
@@ -327,14 +356,14 @@ bool UseTrailingReturnTypeCheck::keepSpecifiers(
327356
if (!F.isConstexpr() && !F.isInlineSpecified() &&
328357
F.getStorageClass() != SC_Extern && F.getStorageClass() != SC_Static &&
329358
!Fr && !(M && M->isVirtualAsWritten()))
330-
return true;
359+
return;
331360

332361
// Tokenize return type. If it contains macros which contain a mix of
333362
// qualifiers, specifiers and types, give up.
334363
llvm::Optional<SmallVector<ClassifiedToken, 8>> MaybeTokens =
335364
classifyTokensBeforeFunctionName(F, Ctx, SM, LangOpts);
336365
if (!MaybeTokens)
337-
return false;
366+
return;
338367

339368
// Find specifiers, remove them from the return type, add them to 'auto'.
340369
unsigned int ReturnTypeBeginOffset =
@@ -367,14 +396,12 @@ bool UseTrailingReturnTypeCheck::keepSpecifiers(
367396
ReturnType.erase(TOffsetInRT, TLengthWithWS);
368397
DeletedChars += TLengthWithWS;
369398
}
370-
371-
return true;
372399
}
373400

374401
void UseTrailingReturnTypeCheck::registerMatchers(MatchFinder *Finder) {
375-
auto F = functionDecl(unless(anyOf(hasTrailingReturn(), returns(voidType()),
376-
returns(autoType()), cxxConversionDecl(),
377-
cxxMethodDecl(isImplicit()))))
402+
auto F = functionDecl(
403+
unless(anyOf(hasTrailingReturn(), returns(voidType()),
404+
cxxConversionDecl(), cxxMethodDecl(isImplicit()))))
378405
.bind("Func");
379406

380407
Finder->addMatcher(F, this);
@@ -397,11 +424,17 @@ void UseTrailingReturnTypeCheck::check(const MatchFinder::MatchResult &Result) {
397424
if (F->getLocation().isInvalid())
398425
return;
399426

427+
// Skip functions which return just 'auto'.
428+
const auto *AT = F->getDeclaredReturnType()->getAs<AutoType>();
429+
if (AT != nullptr && !AT->isConstrained() &&
430+
AT->getKeyword() == AutoTypeKeyword::Auto &&
431+
!hasAnyNestedLocalQualifiers(F->getDeclaredReturnType()))
432+
return;
433+
400434
// TODO: implement those
401435
if (F->getDeclaredReturnType()->isFunctionPointerType() ||
402436
F->getDeclaredReturnType()->isMemberFunctionPointerType() ||
403-
F->getDeclaredReturnType()->isMemberPointerType() ||
404-
F->getDeclaredReturnType()->getAs<DecltypeType>() != nullptr) {
437+
F->getDeclaredReturnType()->isMemberPointerType()) {
405438
diag(F->getLocation(), Message);
406439
return;
407440
}
@@ -435,7 +468,7 @@ void UseTrailingReturnTypeCheck::check(const MatchFinder::MatchResult &Result) {
435468
// discards user formatting and order of const, volatile, type, whitespace,
436469
// space before & ... .
437470
SourceRange ReturnTypeCVRange =
438-
findReturnTypeAndCVSourceRange(*F, Ctx, SM, LangOpts);
471+
findReturnTypeAndCVSourceRange(*F, FTL.getReturnLoc(), Ctx, SM, LangOpts);
439472
if (ReturnTypeCVRange.isInvalid())
440473
return;
441474

clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ class UseTrailingReturnTypeCheck : public ClangTidyCheck {
5050
const SourceManager &SM,
5151
const LangOptions &LangOpts);
5252
SourceRange findReturnTypeAndCVSourceRange(const FunctionDecl &F,
53+
const TypeLoc &ReturnLoc,
5354
const ASTContext &Ctx,
5455
const SourceManager &SM,
5556
const LangOptions &LangOpts);
56-
bool keepSpecifiers(std::string &ReturnType, std::string &Auto,
57+
void keepSpecifiers(std::string &ReturnType, std::string &Auto,
5758
SourceRange ReturnTypeCVRange, const FunctionDecl &F,
5859
const FriendDecl *Fr, const ASTContext &Ctx,
5960
const SourceManager &SM, const LangOptions &LangOpts);

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

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,28 @@ const char SimplifyConditionDiagnostic[] =
5858
const char SimplifyConditionalReturnDiagnostic[] =
5959
"redundant boolean literal in conditional return statement";
6060

61-
const CXXBoolLiteralExpr *getBoolLiteral(const MatchFinder::MatchResult &Result,
62-
StringRef Id) {
63-
const auto *Literal = Result.Nodes.getNodeAs<CXXBoolLiteralExpr>(Id);
64-
return (Literal && Literal->getBeginLoc().isMacroID()) ? nullptr : Literal;
61+
const Expr *getBoolLiteral(const MatchFinder::MatchResult &Result,
62+
StringRef Id) {
63+
if (const Expr *Literal = Result.Nodes.getNodeAs<CXXBoolLiteralExpr>(Id))
64+
return Literal->getBeginLoc().isMacroID() ? nullptr : Literal;
65+
if (const auto *Negated = Result.Nodes.getNodeAs<UnaryOperator>(Id)) {
66+
if (Negated->getOpcode() == UO_LNot &&
67+
isa<CXXBoolLiteralExpr>(Negated->getSubExpr()))
68+
return Negated->getBeginLoc().isMacroID() ? nullptr : Negated;
69+
}
70+
return nullptr;
71+
}
72+
73+
internal::BindableMatcher<Stmt> literalOrNegatedBool(bool Value) {
74+
return expr(anyOf(cxxBoolLiteral(equals(Value)),
75+
unaryOperator(hasUnaryOperand(ignoringParenImpCasts(
76+
cxxBoolLiteral(equals(!Value)))),
77+
hasOperatorName("!"))));
6578
}
6679

6780
internal::Matcher<Stmt> returnsBool(bool Value, StringRef Id = "ignored") {
68-
auto SimpleReturnsBool =
69-
returnStmt(has(cxxBoolLiteral(equals(Value)).bind(Id)))
70-
.bind("returns-bool");
81+
auto SimpleReturnsBool = returnStmt(has(literalOrNegatedBool(Value).bind(Id)))
82+
.bind("returns-bool");
7183
return anyOf(SimpleReturnsBool,
7284
compoundStmt(statementCountIs(1), has(SimpleReturnsBool)));
7385
}
@@ -269,16 +281,25 @@ std::string replacementExpression(const MatchFinder::MatchResult &Result,
269281
return asBool(getText(Result, *E), NeedsStaticCast);
270282
}
271283

272-
const CXXBoolLiteralExpr *stmtReturnsBool(const ReturnStmt *Ret, bool Negated) {
284+
const Expr *stmtReturnsBool(const ReturnStmt *Ret, bool Negated) {
273285
if (const auto *Bool = dyn_cast<CXXBoolLiteralExpr>(Ret->getRetValue())) {
274286
if (Bool->getValue() == !Negated)
275287
return Bool;
276288
}
289+
if (const auto *Unary = dyn_cast<UnaryOperator>(Ret->getRetValue())) {
290+
if (Unary->getOpcode() == UO_LNot) {
291+
if (const auto *Bool =
292+
dyn_cast<CXXBoolLiteralExpr>(Unary->getSubExpr())) {
293+
if (Bool->getValue() == Negated)
294+
return Bool;
295+
}
296+
}
297+
}
277298

278299
return nullptr;
279300
}
280301

281-
const CXXBoolLiteralExpr *stmtReturnsBool(const IfStmt *IfRet, bool Negated) {
302+
const Expr *stmtReturnsBool(const IfStmt *IfRet, bool Negated) {
282303
if (IfRet->getElse() != nullptr)
283304
return nullptr;
284305

@@ -423,7 +444,7 @@ void SimplifyBooleanExprCheck::matchBoolCondition(MatchFinder *Finder,
423444
StringRef BooleanId) {
424445
Finder->addMatcher(
425446
ifStmt(unless(isInTemplateInstantiation()),
426-
hasCondition(cxxBoolLiteral(equals(Value)).bind(BooleanId)))
447+
hasCondition(literalOrNegatedBool(Value).bind(BooleanId)))
427448
.bind(IfStmtId),
428449
this);
429450
}
@@ -433,8 +454,8 @@ void SimplifyBooleanExprCheck::matchTernaryResult(MatchFinder *Finder,
433454
StringRef TernaryId) {
434455
Finder->addMatcher(
435456
conditionalOperator(unless(isInTemplateInstantiation()),
436-
hasTrueExpression(cxxBoolLiteral(equals(Value))),
437-
hasFalseExpression(cxxBoolLiteral(equals(!Value))))
457+
hasTrueExpression(literalOrNegatedBool(Value)),
458+
hasFalseExpression(literalOrNegatedBool(!Value)))
438459
.bind(TernaryId),
439460
this);
440461
}
@@ -465,12 +486,12 @@ void SimplifyBooleanExprCheck::matchIfAssignsBool(MatchFinder *Finder,
465486
auto SimpleThen =
466487
binaryOperator(hasOperatorName("="), hasLHS(anyOf(VarAssign, MemAssign)),
467488
hasLHS(expr().bind(IfAssignVariableId)),
468-
hasRHS(cxxBoolLiteral(equals(Value)).bind(IfAssignLocId)));
489+
hasRHS(literalOrNegatedBool(Value).bind(IfAssignLocId)));
469490
auto Then = anyOf(SimpleThen, compoundStmt(statementCountIs(1),
470491
hasAnySubstatement(SimpleThen)));
471492
auto SimpleElse =
472493
binaryOperator(hasOperatorName("="), hasLHS(anyOf(VarRef, MemRef)),
473-
hasRHS(cxxBoolLiteral(equals(!Value))));
494+
hasRHS(literalOrNegatedBool(!Value)));
474495
auto Else = anyOf(SimpleElse, compoundStmt(statementCountIs(1),
475496
hasAnySubstatement(SimpleElse)));
476497
if (ChainedConditionalAssignment)
@@ -495,7 +516,7 @@ void SimplifyBooleanExprCheck::matchCompoundIfReturnsBool(MatchFinder *Finder,
495516
hasAnySubstatement(
496517
ifStmt(hasThen(returnsBool(Value)), unless(hasElse(stmt())))),
497518
hasAnySubstatement(returnStmt(has(ignoringParenImpCasts(
498-
cxxBoolLiteral(equals(!Value)))))
519+
literalOrNegatedBool(!Value))))
499520
.bind(CompoundReturnId)))
500521
.bind(Id),
501522
this);
@@ -529,10 +550,10 @@ void SimplifyBooleanExprCheck::registerMatchers(MatchFinder *Finder) {
529550
void SimplifyBooleanExprCheck::check(const MatchFinder::MatchResult &Result) {
530551
if (Result.Nodes.getNodeAs<TranslationUnitDecl>("top"))
531552
Visitor(this, Result).TraverseAST(*Result.Context);
532-
else if (const CXXBoolLiteralExpr *TrueConditionRemoved =
553+
else if (const Expr *TrueConditionRemoved =
533554
getBoolLiteral(Result, ConditionThenStmtId))
534555
replaceWithThenStatement(Result, TrueConditionRemoved);
535-
else if (const CXXBoolLiteralExpr *FalseConditionRemoved =
556+
else if (const Expr *FalseConditionRemoved =
536557
getBoolLiteral(Result, ConditionElseStmtId))
537558
replaceWithElseStatement(Result, FalseConditionRemoved);
538559
else if (const auto *Ternary =
@@ -574,17 +595,15 @@ void SimplifyBooleanExprCheck::issueDiag(
574595
}
575596

576597
void SimplifyBooleanExprCheck::replaceWithThenStatement(
577-
const MatchFinder::MatchResult &Result,
578-
const CXXBoolLiteralExpr *TrueConditionRemoved) {
598+
const MatchFinder::MatchResult &Result, const Expr *TrueConditionRemoved) {
579599
const auto *IfStatement = Result.Nodes.getNodeAs<IfStmt>(IfStmtId);
580600
issueDiag(Result, TrueConditionRemoved->getBeginLoc(),
581601
SimplifyConditionDiagnostic, IfStatement->getSourceRange(),
582602
getText(Result, *IfStatement->getThen()));
583603
}
584604

585605
void SimplifyBooleanExprCheck::replaceWithElseStatement(
586-
const MatchFinder::MatchResult &Result,
587-
const CXXBoolLiteralExpr *FalseConditionRemoved) {
606+
const MatchFinder::MatchResult &Result, const Expr *FalseConditionRemoved) {
588607
const auto *IfStatement = Result.Nodes.getNodeAs<IfStmt>(IfStmtId);
589608
const Stmt *ElseStatement = IfStatement->getElse();
590609
issueDiag(Result, FalseConditionRemoved->getBeginLoc(),
@@ -631,7 +650,7 @@ void SimplifyBooleanExprCheck::replaceCompoundReturnWithCondition(
631650
for (++After; After != Compound->body_end() && *Current != Ret;
632651
++Current, ++After) {
633652
if (const auto *If = dyn_cast<IfStmt>(*Current)) {
634-
if (const CXXBoolLiteralExpr *Lit = stmtReturnsBool(If, Negated)) {
653+
if (const Expr *Lit = stmtReturnsBool(If, Negated)) {
635654
if (*After == Ret) {
636655
if (!ChainedConditionalReturn && BeforeIf)
637656
continue;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ class SimplifyBooleanExprCheck : public ClangTidyCheck {
5151

5252
void
5353
replaceWithThenStatement(const ast_matchers::MatchFinder::MatchResult &Result,
54-
const CXXBoolLiteralExpr *BoolLiteral);
54+
const Expr *BoolLiteral);
5555

5656
void
5757
replaceWithElseStatement(const ast_matchers::MatchFinder::MatchResult &Result,
58-
const CXXBoolLiteralExpr *FalseConditionRemoved);
58+
const Expr *FalseConditionRemoved);
5959

6060
void
6161
replaceWithCondition(const ast_matchers::MatchFinder::MatchResult &Result,

clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path,
8484
extra_arg, extra_arg_before, quiet, config):
8585
"""Gets a command line for clang-tidy."""
8686
start = [clang_tidy_binary]
87-
if allow_enabling_alpha_checkers is not None:
87+
if allow_enabling_alpha_checkers:
8888
start.append('-allow-enabling-analyzer-alpha-checkers')
8989
if header_filter is not None:
9090
start.append('-header-filter=' + header_filter)

0 commit comments

Comments
 (0)