Skip to content

Commit f728308

Browse files
authored
LLVM and LLVM-SPIRV-Translator pulldown
LLVM: 4b8632e LLVM-SPIRV-Translator: KhronosGroup/SPIRV-LLVM-Translator@1b546773
2 parents 98702d3 + 7e078f7 commit f728308

File tree

1,829 files changed

+52214
-26543
lines changed

Some content is hidden

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

1,829 files changed

+52214
-26543
lines changed

clang-tools-extra/clang-query/Query.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ bool HelpQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
4343
"Set whether to bind the root matcher to \"root\".\n"
4444
" set print-matcher (true|false) "
4545
"Set whether to print the current matcher,\n"
46+
" set traversal <kind> "
47+
"Set traversal kind of clang-query session. Available kinds are:\n"
48+
" AsIs "
49+
"Print and match the AST as clang sees it.\n"
50+
" IgnoreImplicitCastsAndParentheses "
51+
"Omit implicit casts and parens in matching and dumping.\n"
52+
" IgnoreUnlessSpelledInSource "
53+
"Omit AST nodes unless spelled in the source. This mode is the "
54+
"default.\n"
4655
" set output <feature> "
4756
"Set whether to output only <feature> content.\n"
4857
" enable output <feature> "
@@ -98,6 +107,8 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
98107
OS << "Not a valid top-level matcher.\n";
99108
return false;
100109
}
110+
111+
AST->getASTContext().getParentMapContext().setTraversalKind(QS.TK);
101112
Finder.matchAST(AST->getASTContext());
102113

103114
if (QS.PrintMatcher) {
@@ -148,6 +159,7 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
148159
const SourceManager &SM = Ctx.getSourceManager();
149160
ASTDumper Dumper(OS, &Ctx.getCommentCommandTraits(), &SM,
150161
SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
162+
Dumper.SetTraversalKind(QS.TK);
151163
Dumper.Visit(BI->second);
152164
OS << "\n";
153165
}

clang-tools-extra/clang-query/Query.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ enum QueryKind {
2828
QK_Match,
2929
QK_SetBool,
3030
QK_SetOutputKind,
31+
QK_SetTraversalKind,
3132
QK_EnableOutputKind,
3233
QK_DisableOutputKind,
3334
QK_Quit
@@ -119,6 +120,10 @@ template <> struct SetQueryKind<OutputKind> {
119120
static const QueryKind value = QK_SetOutputKind;
120121
};
121122

123+
template <> struct SetQueryKind<ast_type_traits::TraversalKind> {
124+
static const QueryKind value = QK_SetTraversalKind;
125+
};
126+
122127
/// Query for "set VAR VALUE".
123128
template <typename T> struct SetQuery : Query {
124129
SetQuery(T QuerySession::*Var, T Value)

clang-tools-extra/clang-query/QueryParser.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,24 @@ template <typename QueryType> QueryRef QueryParser::parseSetOutputKind() {
128128
llvm_unreachable("Invalid output kind");
129129
}
130130

131+
QueryRef QueryParser::parseSetTraversalKind(
132+
ast_type_traits::TraversalKind QuerySession::*Var) {
133+
StringRef ValStr;
134+
unsigned Value =
135+
LexOrCompleteWord<unsigned>(this, ValStr)
136+
.Case("AsIs", ast_type_traits::TK_AsIs)
137+
.Case("IgnoreImplicitCastsAndParentheses",
138+
ast_type_traits::TK_IgnoreImplicitCastsAndParentheses)
139+
.Case("IgnoreUnlessSpelledInSource",
140+
ast_type_traits::TK_IgnoreUnlessSpelledInSource)
141+
.Default(~0u);
142+
if (Value == ~0u) {
143+
return new InvalidQuery("expected traversal kind, got '" + ValStr + "'");
144+
}
145+
return new SetQuery<ast_type_traits::TraversalKind>(
146+
Var, static_cast<ast_type_traits::TraversalKind>(Value));
147+
}
148+
131149
QueryRef QueryParser::endQuery(QueryRef Q) {
132150
StringRef Extra = Line;
133151
StringRef ExtraTrimmed = Extra.drop_while(
@@ -171,7 +189,8 @@ enum ParsedQueryVariable {
171189
PQV_Invalid,
172190
PQV_Output,
173191
PQV_BindRoot,
174-
PQV_PrintMatcher
192+
PQV_PrintMatcher,
193+
PQV_Traversal
175194
};
176195

177196
QueryRef makeInvalidQueryFromDiagnostics(const Diagnostics &Diag) {
@@ -272,6 +291,7 @@ QueryRef QueryParser::doParse() {
272291
.Case("output", PQV_Output)
273292
.Case("bind-root", PQV_BindRoot)
274293
.Case("print-matcher", PQV_PrintMatcher)
294+
.Case("traversal", PQV_Traversal)
275295
.Default(PQV_Invalid);
276296
if (VarStr.empty())
277297
return new InvalidQuery("expected variable name");
@@ -289,6 +309,9 @@ QueryRef QueryParser::doParse() {
289309
case PQV_PrintMatcher:
290310
Q = parseSetBool(&QuerySession::PrintMatcher);
291311
break;
312+
case PQV_Traversal:
313+
Q = parseSetTraversalKind(&QuerySession::TK);
314+
break;
292315
case PQV_Invalid:
293316
llvm_unreachable("Invalid query kind");
294317
}

clang-tools-extra/clang-query/QueryParser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class QueryParser {
4343
template <typename T> struct LexOrCompleteWord;
4444

4545
QueryRef parseSetBool(bool QuerySession::*Var);
46+
QueryRef
47+
parseSetTraversalKind(ast_type_traits::TraversalKind QuerySession::*Var);
4648
template <typename QueryType> QueryRef parseSetOutputKind();
4749
QueryRef completeMatcherExpression();
4850

clang-tools-extra/clang-query/QuerySession.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_QUERY_QUERY_SESSION_H
1010
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_QUERY_QUERY_SESSION_H
1111

12+
#include "clang/AST/ASTTypeTraits.h"
1213
#include "clang/ASTMatchers/Dynamic/VariantValue.h"
1314
#include "llvm/ADT/ArrayRef.h"
1415
#include "llvm/ADT/StringMap.h"
@@ -25,7 +26,7 @@ class QuerySession {
2526
QuerySession(llvm::ArrayRef<std::unique_ptr<ASTUnit>> ASTs)
2627
: ASTs(ASTs), PrintOutput(false), DiagOutput(true),
2728
DetailedASTOutput(false), BindRoot(true), PrintMatcher(false),
28-
Terminate(false) {}
29+
Terminate(false), TK(ast_type_traits::TK_IgnoreUnlessSpelledInSource) {}
2930

3031
llvm::ArrayRef<std::unique_ptr<ASTUnit>> ASTs;
3132

@@ -36,6 +37,8 @@ class QuerySession {
3637
bool BindRoot;
3738
bool PrintMatcher;
3839
bool Terminate;
40+
41+
ast_type_traits::TraversalKind TK;
3942
llvm::StringMap<ast_matchers::dynamic::VariantValue> NamedValues;
4043
};
4144

clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ findMembersUsedInInitExpr(const CXXCtorInitializer *Initializer,
104104
// for those accesses Sema::PerformObjectMemberConversion always inserts an
105105
// UncheckedDerivedToBase ImplicitCastExpr between the this expr and the
106106
// object expression
107-
auto FoundExprs =
108-
match(findAll(memberExpr(hasObjectExpression(cxxThisExpr())).bind("ME")),
109-
*Initializer->getInit(), Context);
107+
auto FoundExprs = match(
108+
traverse(
109+
TK_AsIs,
110+
findAll(memberExpr(hasObjectExpression(cxxThisExpr())).bind("ME"))),
111+
*Initializer->getInit(), Context);
110112
for (BoundNodes &BN : FoundExprs)
111113
if (auto *MemExpr = BN.getNodeAs<MemberExpr>("ME"))
112114
if (auto *FD = dyn_cast<FieldDecl>(MemExpr->getMemberDecl()))

clang-tools-extra/clang-tidy/abseil/DurationDivisionCheck.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ void DurationDivisionCheck::registerMatchers(MatchFinder *finder) {
2020
const auto DurationExpr =
2121
expr(hasType(cxxRecordDecl(hasName("::absl::Duration"))));
2222
finder->addMatcher(
23-
implicitCastExpr(
24-
hasSourceExpression(ignoringParenCasts(
25-
cxxOperatorCallExpr(hasOverloadedOperatorName("/"),
26-
hasArgument(0, DurationExpr),
27-
hasArgument(1, DurationExpr))
28-
.bind("OpCall"))),
29-
hasImplicitDestinationType(qualType(unless(isInteger()))),
30-
unless(hasParent(cxxStaticCastExpr())),
31-
unless(hasParent(cStyleCastExpr())),
32-
unless(isInTemplateInstantiation())),
23+
traverse(ast_type_traits::TK_AsIs,
24+
implicitCastExpr(
25+
hasSourceExpression(ignoringParenCasts(
26+
cxxOperatorCallExpr(hasOverloadedOperatorName("/"),
27+
hasArgument(0, DurationExpr),
28+
hasArgument(1, DurationExpr))
29+
.bind("OpCall"))),
30+
hasImplicitDestinationType(qualType(unless(isInteger()))),
31+
unless(hasParent(cxxStaticCastExpr())),
32+
unless(hasParent(cStyleCastExpr())),
33+
unless(isInTemplateInstantiation()))),
3334
this);
3435
}
3536

clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,23 @@ void FasterStrsplitDelimiterCheck::registerMatchers(MatchFinder *Finder) {
7878

7979
// Find uses of absl::StrSplit(..., "x") and absl::StrSplit(...,
8080
// absl::ByAnyChar("x")) to transform them into absl::StrSplit(..., 'x').
81-
Finder->addMatcher(callExpr(callee(functionDecl(hasName("::absl::StrSplit"))),
82-
hasArgument(1, anyOf(ByAnyCharArg, SingleChar)),
83-
unless(isInTemplateInstantiation()))
84-
.bind("StrSplit"),
85-
this);
81+
Finder->addMatcher(
82+
traverse(ast_type_traits::TK_AsIs,
83+
callExpr(callee(functionDecl(hasName("::absl::StrSplit"))),
84+
hasArgument(1, anyOf(ByAnyCharArg, SingleChar)),
85+
unless(isInTemplateInstantiation()))
86+
.bind("StrSplit")),
87+
this);
8688

8789
// Find uses of absl::MaxSplits("x", N) and
8890
// absl::MaxSplits(absl::ByAnyChar("x"), N) to transform them into
8991
// absl::MaxSplits('x', N).
9092
Finder->addMatcher(
91-
callExpr(
92-
callee(functionDecl(hasName("::absl::MaxSplits"))),
93-
hasArgument(0, anyOf(ByAnyCharArg, ignoringParenCasts(SingleChar))),
94-
unless(isInTemplateInstantiation())),
93+
traverse(ast_type_traits::TK_AsIs,
94+
callExpr(callee(functionDecl(hasName("::absl::MaxSplits"))),
95+
hasArgument(0, anyOf(ByAnyCharArg,
96+
ignoringParenCasts(SingleChar))),
97+
unless(isInTemplateInstantiation()))),
9598
this);
9699
}
97100

clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ const clang::CallExpr* ProcessArgument(const Expr* Arg,
6464
static const auto* const Strcat = new auto(hasName("::absl::StrCat"));
6565
const auto IsStrcat = cxxBindTemporaryExpr(
6666
has(callExpr(callee(functionDecl(*Strcat))).bind("StrCat")));
67-
if (const auto* SubStrcatCall = selectFirst<const CallExpr>(
67+
if (const auto *SubStrcatCall = selectFirst<const CallExpr>(
6868
"StrCat",
69-
match(stmt(anyOf(
70-
cxxConstructExpr(IsAlphanum, hasArgument(0, IsStrcat)),
71-
IsStrcat)),
69+
match(stmt(traverse(ast_type_traits::TK_AsIs,
70+
anyOf(cxxConstructExpr(IsAlphanum,
71+
hasArgument(0, IsStrcat)),
72+
IsStrcat))),
7273
*Arg->IgnoreParenImpCasts(), *Result.Context))) {
7374
RemoveCallLeaveArgs(SubStrcatCall, CheckResult);
7475
return SubStrcatCall;

clang-tools-extra/clang-tidy/abseil/StrCatAppendCheck.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,17 @@ void StrCatAppendCheck::registerMatchers(MatchFinder *Finder) {
5858
// StrCat on the RHS. The first argument of the StrCat call should be the same
5959
// as the LHS. Ignore calls from template instantiations.
6060
Finder->addMatcher(
61-
cxxOperatorCallExpr(
62-
unless(isInTemplateInstantiation()), hasOverloadedOperatorName("="),
63-
hasArgument(0, declRefExpr(to(decl().bind("LHS")))),
64-
hasArgument(1, IgnoringTemporaries(
65-
callExpr(callee(StrCat), hasArgument(0, AlphaNum),
66-
unless(HasAnotherReferenceToLhs))
67-
.bind("Call"))))
68-
.bind("Op"),
61+
traverse(ast_type_traits::TK_AsIs,
62+
cxxOperatorCallExpr(
63+
unless(isInTemplateInstantiation()),
64+
hasOverloadedOperatorName("="),
65+
hasArgument(0, declRefExpr(to(decl().bind("LHS")))),
66+
hasArgument(
67+
1, IgnoringTemporaries(
68+
callExpr(callee(StrCat), hasArgument(0, AlphaNum),
69+
unless(HasAnotherReferenceToLhs))
70+
.bind("Call"))))
71+
.bind("Op")),
6972
this);
7073
}
7174

clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ void StringFindStartswithCheck::registerMatchers(MatchFinder *Finder) {
5252
// Match [=!]= with a zero on one side and a string.find on the other.
5353
binaryOperator(
5454
hasAnyOperatorName("==", "!="),
55-
hasEitherOperand(ignoringParenImpCasts(ZeroLiteral)),
56-
hasEitherOperand(ignoringParenImpCasts(StringFind.bind("findexpr"))))
55+
hasOperands(ignoringParenImpCasts(ZeroLiteral),
56+
ignoringParenImpCasts(StringFind.bind("findexpr"))))
5757
.bind("expr"),
5858
this);
5959
}

clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,17 @@ void UpgradeDurationConversionsCheck::registerMatchers(MatchFinder *Finder) {
9999
// `absl::Hours(x)`
100100
// where `x` is not of a built-in type.
101101
Finder->addMatcher(
102-
implicitCastExpr(
103-
anyOf(hasCastKind(CK_UserDefinedConversion),
104-
has(implicitCastExpr(hasCastKind(CK_UserDefinedConversion)))),
105-
hasParent(callExpr(
106-
callee(functionDecl(DurationFactoryFunction(),
107-
unless(hasParent(functionTemplateDecl())))),
108-
hasArgument(0, expr().bind("arg")))))
109-
.bind("OuterExpr"),
102+
traverse(
103+
ast_type_traits::TK_AsIs,
104+
implicitCastExpr(anyOf(hasCastKind(CK_UserDefinedConversion),
105+
has(implicitCastExpr(
106+
hasCastKind(CK_UserDefinedConversion)))),
107+
hasParent(callExpr(
108+
callee(functionDecl(
109+
DurationFactoryFunction(),
110+
unless(hasParent(functionTemplateDecl())))),
111+
hasArgument(0, expr().bind("arg")))))
112+
.bind("OuterExpr")),
110113
this);
111114
}
112115

@@ -116,6 +119,8 @@ void UpgradeDurationConversionsCheck::check(
116119
"implicit conversion to 'int64_t' is deprecated in this context; use an "
117120
"explicit cast instead";
118121

122+
TraversalKindScope RAII(*Result.Context, ast_type_traits::TK_AsIs);
123+
119124
const auto *ArgExpr = Result.Nodes.getNodeAs<Expr>("arg");
120125
SourceLocation Loc = ArgExpr->getBeginLoc();
121126

clang-tools-extra/clang-tidy/add_new_check.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env python
22
#
3-
#===- add_new_check.py - clang-tidy check generator ----------*- python -*--===#
3+
#===- add_new_check.py - clang-tidy check generator ---------*- python -*--===#
44
#
55
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
66
# See https://llvm.org/LICENSE.txt for license information.
77
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
88
#
9-
#===------------------------------------------------------------------------===#
9+
#===-----------------------------------------------------------------------===#
1010

1111
from __future__ import print_function
1212

@@ -15,8 +15,9 @@
1515
import re
1616
import sys
1717

18-
# Adapts the module's CMakelist file. Returns 'True' if it could add a new entry
19-
# and 'False' if the entry already existed.
18+
19+
# Adapts the module's CMakelist file. Returns 'True' if it could add a new
20+
# entry and 'False' if the entry already existed.
2021
def adapt_cmake(module_path, check_name_camel):
2122
filename = os.path.join(module_path, 'CMakeLists.txt')
2223
with open(filename, 'r') as f:
@@ -227,7 +228,6 @@ def add_release_notes(module_path, module, check_name):
227228
with open(filename, 'w') as f:
228229
note_added = False
229230
header_found = False
230-
next_header_found = False
231231
add_note_here = False
232232

233233
for line in lines:
@@ -241,7 +241,6 @@ def add_release_notes(module_path, module, check_name):
241241
add_note_here = True
242242

243243
if match_next:
244-
next_header_found = True
245244
add_note_here = True
246245

247246
if match:

clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ void AssertSideEffectCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
8484

8585
void AssertSideEffectCheck::registerMatchers(MatchFinder *Finder) {
8686
auto DescendantWithSideEffect =
87-
hasDescendant(expr(hasSideEffect(CheckFunctionCalls)));
87+
traverse(ast_type_traits::TK_AsIs,
88+
hasDescendant(expr(hasSideEffect(CheckFunctionCalls))));
8889
auto ConditionWithSideEffect = hasCondition(DescendantWithSideEffect);
8990
Finder->addMatcher(
9091
stmt(

clang-tools-extra/clang-tidy/bugprone/BoolPointerImplicitConversionCheck.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ void BoolPointerImplicitConversionCheck::registerMatchers(MatchFinder *Finder) {
1818
// Look for ifs that have an implicit bool* to bool conversion in the
1919
// condition. Filter negations.
2020
Finder->addMatcher(
21-
ifStmt(hasCondition(findAll(implicitCastExpr(
22-
unless(hasParent(unaryOperator(hasOperatorName("!")))),
23-
hasSourceExpression(
24-
expr(hasType(pointerType(pointee(booleanType()))),
25-
ignoringParenImpCasts(declRefExpr().bind("expr")))),
26-
hasCastKind(CK_PointerToBoolean)))),
27-
unless(isInTemplateInstantiation()))
28-
.bind("if"),
21+
traverse(
22+
ast_type_traits::TK_AsIs,
23+
ifStmt(hasCondition(findAll(implicitCastExpr(
24+
unless(hasParent(unaryOperator(hasOperatorName("!")))),
25+
hasSourceExpression(expr(
26+
hasType(pointerType(pointee(booleanType()))),
27+
ignoringParenImpCasts(declRefExpr().bind("expr")))),
28+
hasCastKind(CK_PointerToBoolean)))),
29+
unless(isInTemplateInstantiation()))
30+
.bind("if")),
2931
this);
3032
}
3133

0 commit comments

Comments
 (0)