Skip to content

Commit 9c2035a

Browse files
authored
Merge pull request #862
LLVM and SPIRV translator pulldown
2 parents 0543397 + 1bd4f52 commit 9c2035a

File tree

1,850 files changed

+50829
-19628
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,850 files changed

+50829
-19628
lines changed

clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ def main():
8989
database = json.load(open(os.path.join(build_path, db_path)))
9090
files = [entry['file'] for entry in database]
9191

92+
# Filter out .rc files on Windows. CMake includes them for some reason.
93+
files = [f for f in files if not f.endswith('.rc')]
94+
9295
max_task = args.j
9396
if max_task == 0:
9497
max_task = multiprocessing.cpu_count()
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//===--- BadSignalToKillThreadCheck.cpp - clang-tidy ---------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "BadSignalToKillThreadCheck.h"
10+
#include "clang/AST/ASTContext.h"
11+
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
13+
using namespace clang::ast_matchers;
14+
15+
namespace clang {
16+
namespace tidy {
17+
namespace bugprone {
18+
19+
void BadSignalToKillThreadCheck::registerMatchers(MatchFinder *Finder) {
20+
Finder->addMatcher(
21+
callExpr(allOf(callee(functionDecl(hasName("::pthread_kill"))),
22+
argumentCountIs(2)),
23+
hasArgument(1, integerLiteral().bind("integer-literal")))
24+
.bind("thread-kill"),
25+
this);
26+
}
27+
28+
static Preprocessor *PP;
29+
30+
void BadSignalToKillThreadCheck::check(const MatchFinder::MatchResult &Result) {
31+
const auto IsSigterm = [](const auto &KeyValue) -> bool {
32+
return KeyValue.first->getName() == "SIGTERM";
33+
};
34+
const auto TryExpandAsInteger =
35+
[](Preprocessor::macro_iterator It) -> Optional<unsigned> {
36+
if (It == PP->macro_end())
37+
return llvm::None;
38+
const MacroInfo *MI = PP->getMacroInfo(It->first);
39+
const Token &T = MI->tokens().back();
40+
StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
41+
42+
llvm::APInt IntValue;
43+
constexpr unsigned AutoSenseRadix = 0;
44+
if (ValueStr.getAsInteger(AutoSenseRadix, IntValue))
45+
return llvm::None;
46+
return IntValue.getZExtValue();
47+
};
48+
49+
const auto SigtermMacro = llvm::find_if(PP->macros(), IsSigterm);
50+
51+
if (!SigtermValue && !(SigtermValue = TryExpandAsInteger(SigtermMacro)))
52+
return;
53+
54+
const auto *MatchedExpr = Result.Nodes.getNodeAs<Expr>("thread-kill");
55+
const auto *MatchedIntLiteral =
56+
Result.Nodes.getNodeAs<IntegerLiteral>("integer-literal");
57+
if (MatchedIntLiteral->getValue() == *SigtermValue) {
58+
diag(MatchedExpr->getBeginLoc(),
59+
"thread should not be terminated by raising the 'SIGTERM' signal");
60+
}
61+
}
62+
63+
void BadSignalToKillThreadCheck::registerPPCallbacks(
64+
const SourceManager &SM, Preprocessor *pp, Preprocessor *ModuleExpanderPP) {
65+
PP = pp;
66+
}
67+
68+
} // namespace bugprone
69+
} // namespace tidy
70+
} // namespace clang
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===--- BadSignalToKillThreadCheck.h - clang-tidy --------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BADSIGNALTOKILLTHREADCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BADSIGNALTOKILLTHREADCHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang {
15+
namespace tidy {
16+
namespace bugprone {
17+
18+
/// Finds ``pthread_kill`` function calls when thread is terminated by
19+
/// ``SIGTERM`` signal.
20+
/// For the user-facing documentation see:
21+
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-bad-signal-to-kill-thread.html
22+
class BadSignalToKillThreadCheck : public ClangTidyCheck {
23+
public:
24+
BadSignalToKillThreadCheck(StringRef Name, ClangTidyContext *Context)
25+
: ClangTidyCheck(Name, Context) {}
26+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
27+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
28+
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
29+
Preprocessor *ModuleExpanderPP) override;
30+
Optional<unsigned> SigtermValue;
31+
};
32+
33+
} // namespace bugprone
34+
} // namespace tidy
35+
} // namespace clang
36+
37+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BADSIGNALTOKILLTHREADCHECK_H

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "../cppcoreguidelines/NarrowingConversionsCheck.h"
1313
#include "ArgumentCommentCheck.h"
1414
#include "AssertSideEffectCheck.h"
15+
#include "BadSignalToKillThreadCheck.h"
1516
#include "BoolPointerImplicitConversionCheck.h"
1617
#include "BranchCloneCheck.h"
1718
#include "CopyConstructorInitCheck.h"
@@ -68,6 +69,8 @@ class BugproneModule : public ClangTidyModule {
6869
"bugprone-argument-comment");
6970
CheckFactories.registerCheck<AssertSideEffectCheck>(
7071
"bugprone-assert-side-effect");
72+
CheckFactories.registerCheck<BadSignalToKillThreadCheck>(
73+
"bugprone-bad-signal-to-kill-thread");
7174
CheckFactories.registerCheck<BoolPointerImplicitConversionCheck>(
7275
"bugprone-bool-pointer-implicit-conversion");
7376
CheckFactories.registerCheck<BranchCloneCheck>(

clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS support)
33
add_clang_library(clangTidyBugproneModule
44
ArgumentCommentCheck.cpp
55
AssertSideEffectCheck.cpp
6+
BadSignalToKillThreadCheck.cpp
67
BoolPointerImplicitConversionCheck.cpp
78
BranchCloneCheck.cpp
89
BugproneTidyModule.cpp

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "MacroRepeatedSideEffectsCheck.h"
10+
#include "clang/Basic/Builtins.h"
1011
#include "clang/Frontend/CompilerInstance.h"
1112
#include "clang/Lex/MacroArgs.h"
1213
#include "clang/Lex/PPCallbacks.h"

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

100755100644
File mode changed.

clang-tools-extra/clang-tidy/bugprone/ParentVirtualCallCheck.h

100755100644
File mode changed.

clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "../ClangTidyModule.h"
1111
#include "../ClangTidyModuleRegistry.h"
1212
#include "../bugprone/UnhandledSelfAssignmentCheck.h"
13+
#include "../bugprone/BadSignalToKillThreadCheck.h"
1314
#include "../google/UnnamedNamespaceInHeaderCheck.h"
1415
#include "../misc/NewDeleteOverloadsCheck.h"
1516
#include "../misc/NonCopyableObjects.h"
@@ -82,6 +83,9 @@ class CERTModule : public ClangTidyModule {
8283
CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc30-c");
8384
CheckFactories.registerCheck<ProperlySeededRandomGeneratorCheck>(
8485
"cert-msc32-c");
86+
// POS
87+
CheckFactories.registerCheck<bugprone::BadSignalToKillThreadCheck>(
88+
"cert-pos44-c");
8589
}
8690

8791
ClangTidyOptions getModuleOptions() override {

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ namespace modernize {
2020
UseOverrideCheck::UseOverrideCheck(StringRef Name, ClangTidyContext *Context)
2121
: ClangTidyCheck(Name, Context),
2222
IgnoreDestructors(Options.get("IgnoreDestructors", false)),
23+
AllowOverrideAndFinal(Options.get("AllowOverrideAndFinal", false)),
2324
OverrideSpelling(Options.get("OverrideSpelling", "override")),
2425
FinalSpelling(Options.get("FinalSpelling", "final")) {}
2526

2627
void UseOverrideCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
2728
Options.store(Opts, "IgnoreDestructors", IgnoreDestructors);
29+
Options.store(Opts, "AllowOverrideAndFinal", AllowOverrideAndFinal);
2830
Options.store(Opts, "OverrideSpelling", OverrideSpelling);
2931
Options.store(Opts, "FinalSpelling", FinalSpelling);
3032
}
@@ -103,7 +105,8 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) {
103105
bool OnlyVirtualSpecified = HasVirtual && !HasOverride && !HasFinal;
104106
unsigned KeywordCount = HasVirtual + HasOverride + HasFinal;
105107

106-
if (!OnlyVirtualSpecified && KeywordCount == 1)
108+
if ((!OnlyVirtualSpecified && KeywordCount == 1) ||
109+
(!HasVirtual && HasOverride && HasFinal && AllowOverrideAndFinal))
107110
return; // Nothing to do.
108111

109112
std::string Message;
@@ -113,8 +116,9 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) {
113116
Message = "annotate this function with '%0' or (rarely) '%1'";
114117
} else {
115118
StringRef Redundant =
116-
HasVirtual ? (HasOverride && HasFinal ? "'virtual' and '%0' are"
117-
: "'virtual' is")
119+
HasVirtual ? (HasOverride && HasFinal && !AllowOverrideAndFinal
120+
? "'virtual' and '%0' are"
121+
: "'virtual' is")
118122
: "'%0' is";
119123
StringRef Correct = HasFinal ? "'%1'" : "'%0'";
120124

@@ -211,7 +215,7 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) {
211215
Diag << FixItHint::CreateInsertion(InsertLoc, ReplacementText);
212216
}
213217

214-
if (HasFinal && HasOverride) {
218+
if (HasFinal && HasOverride && !AllowOverrideAndFinal) {
215219
SourceLocation OverrideLoc = Method->getAttr<OverrideAttr>()->getLocation();
216220
Diag << FixItHint::CreateRemoval(
217221
CharSourceRange::getTokenRange(OverrideLoc, OverrideLoc));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class UseOverrideCheck : public ClangTidyCheck {
2626

2727
private:
2828
const bool IgnoreDestructors;
29+
const bool AllowOverrideAndFinal;
2930
const std::string OverrideSpelling;
3031
const std::string FinalSpelling;
3132
};

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

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,46 @@ static bool CheckRemoval(SourceManager &SM, SourceLocation StartLoc,
3939
File.begin(), TokenBegin, File.end());
4040

4141
Token Tok;
42-
int ParenLevel = 0;
42+
int NestingLevel = 0; // Parens, braces, and square brackets
43+
int AngleBracketLevel = 0;
4344
bool FoundTypedef = false;
4445

4546
while (!DeclLexer.LexFromRawLexer(Tok) && !Tok.is(tok::semi)) {
4647
switch (Tok.getKind()) {
4748
case tok::l_brace:
48-
case tok::r_brace:
49-
// This might be the `typedef struct {...} T;` case.
50-
return false;
49+
if (NestingLevel == 0 && AngleBracketLevel == 0) {
50+
// At top level, this might be the `typedef struct {...} T;` case.
51+
// Inside parens, square brackets, or angle brackets it's not.
52+
return false;
53+
}
54+
++NestingLevel;
55+
break;
5156
case tok::l_paren:
52-
ParenLevel++;
57+
case tok::l_square:
58+
++NestingLevel;
5359
break;
60+
case tok::r_brace:
5461
case tok::r_paren:
55-
ParenLevel--;
62+
case tok::r_square:
63+
--NestingLevel;
64+
break;
65+
case tok::less:
66+
// If not nested in paren/brace/square bracket, treat as opening angle bracket.
67+
if (NestingLevel == 0)
68+
++AngleBracketLevel;
69+
break;
70+
case tok::greater:
71+
// Per C++ 17 Draft N4659, Section 17.2/3
72+
// https://timsong-cpp.github.io/cppwp/n4659/temp.names#3:
73+
// "When parsing a template-argument-list, the first non-nested > is
74+
// taken as the ending delimiter rather than a greater-than operator."
75+
// If not nested in paren/brace/square bracket, treat as closing angle bracket.
76+
if (NestingLevel == 0)
77+
--AngleBracketLevel;
5678
break;
5779
case tok::comma:
58-
if (ParenLevel == 0) {
59-
// If there is comma and we are not between open parenthesis then it is
60-
// two or more declarations in this chain.
80+
if (NestingLevel == 0 && AngleBracketLevel == 0) {
81+
// If there is a non-nested comma we have two or more declarations in this chain.
6182
return false;
6283
}
6384
break;
@@ -88,8 +109,7 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
88109
if (StartLoc.isMacroID() && IgnoreMacros)
89110
return;
90111

91-
auto Diag =
92-
diag(StartLoc, "use 'using' instead of 'typedef'");
112+
auto Diag = diag(StartLoc, "use 'using' instead of 'typedef'");
93113

94114
// do not fix if there is macro or array
95115
if (MatchedDecl->getUnderlyingType()->isArrayType() || StartLoc.isMacroID())

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

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "RedundantStringInitCheck.h"
1010
#include "../utils/Matchers.h"
11+
#include "../utils/OptionsUtils.h"
1112
#include "clang/ASTMatchers/ASTMatchers.h"
1213

1314
using namespace clang::ast_matchers;
@@ -17,19 +18,43 @@ namespace clang {
1718
namespace tidy {
1819
namespace readability {
1920

21+
const char DefaultStringNames[] = "::std::basic_string";
22+
23+
RedundantStringInitCheck::RedundantStringInitCheck(StringRef Name,
24+
ClangTidyContext *Context)
25+
: ClangTidyCheck(Name, Context),
26+
StringNames(utils::options::parseStringList(
27+
Options.get("StringNames", DefaultStringNames))) {}
28+
29+
void RedundantStringInitCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
30+
Options.store(Opts, "StringNames", DefaultStringNames);
31+
}
32+
2033
void RedundantStringInitCheck::registerMatchers(MatchFinder *Finder) {
2134
if (!getLangOpts().CPlusPlus)
2235
return;
36+
const auto hasStringTypeName = hasAnyName(
37+
SmallVector<StringRef, 3>(StringNames.begin(), StringNames.end()));
38+
39+
// Version of StringNames with namespaces removed
40+
std::vector<std::string> stringNamesNoNamespace;
41+
for (const std::string &name : StringNames) {
42+
std::string::size_type colonPos = name.rfind(':');
43+
stringNamesNoNamespace.push_back(
44+
name.substr(colonPos == std::string::npos ? 0 : colonPos + 1));
45+
}
46+
const auto hasStringCtorName = hasAnyName(SmallVector<StringRef, 3>(
47+
stringNamesNoNamespace.begin(), stringNamesNoNamespace.end()));
2348

2449
// Match string constructor.
25-
const auto StringConstructorExpr = expr(anyOf(
26-
cxxConstructExpr(argumentCountIs(1),
27-
hasDeclaration(cxxMethodDecl(hasName("basic_string")))),
28-
// If present, the second argument is the alloc object which must not
29-
// be present explicitly.
30-
cxxConstructExpr(argumentCountIs(2),
31-
hasDeclaration(cxxMethodDecl(hasName("basic_string"))),
32-
hasArgument(1, cxxDefaultArgExpr()))));
50+
const auto StringConstructorExpr = expr(
51+
anyOf(cxxConstructExpr(argumentCountIs(1),
52+
hasDeclaration(cxxMethodDecl(hasStringCtorName))),
53+
// If present, the second argument is the alloc object which must
54+
// not be present explicitly.
55+
cxxConstructExpr(argumentCountIs(2),
56+
hasDeclaration(cxxMethodDecl(hasStringCtorName)),
57+
hasArgument(1, cxxDefaultArgExpr()))));
3358

3459
// Match a string constructor expression with an empty string literal.
3560
const auto EmptyStringCtorExpr = cxxConstructExpr(
@@ -46,23 +71,23 @@ void RedundantStringInitCheck::registerMatchers(MatchFinder *Finder) {
4671
// string bar("");
4772
Finder->addMatcher(
4873
namedDecl(
49-
varDecl(hasType(hasUnqualifiedDesugaredType(recordType(
50-
hasDeclaration(cxxRecordDecl(hasName("basic_string")))))),
51-
hasInitializer(expr(ignoringImplicit(anyOf(
52-
EmptyStringCtorExpr,
53-
EmptyStringCtorExprWithTemporaries)))
54-
.bind("expr"))),
55-
unless(parmVarDecl()))
56-
.bind("decl"),
74+
varDecl(
75+
hasType(hasUnqualifiedDesugaredType(recordType(
76+
hasDeclaration(cxxRecordDecl(hasStringTypeName))))),
77+
hasInitializer(expr(ignoringImplicit(anyOf(
78+
EmptyStringCtorExpr, EmptyStringCtorExprWithTemporaries)))))
79+
.bind("vardecl"),
80+
unless(parmVarDecl())),
5781
this);
5882
}
5983

6084
void RedundantStringInitCheck::check(const MatchFinder::MatchResult &Result) {
61-
const auto *CtorExpr = Result.Nodes.getNodeAs<Expr>("expr");
62-
const auto *Decl = Result.Nodes.getNodeAs<NamedDecl>("decl");
63-
diag(CtorExpr->getExprLoc(), "redundant string initialization")
64-
<< FixItHint::CreateReplacement(CtorExpr->getSourceRange(),
65-
Decl->getName());
85+
const auto *VDecl = Result.Nodes.getNodeAs<VarDecl>("vardecl");
86+
// VarDecl's getSourceRange() spans 'string foo = ""' or 'string bar("")'.
87+
// So start at getLocation() to span just 'foo = ""' or 'bar("")'.
88+
SourceRange ReplaceRange(VDecl->getLocation(), VDecl->getEndLoc());
89+
diag(VDecl->getLocation(), "redundant string initialization")
90+
<< FixItHint::CreateReplacement(ReplaceRange, VDecl->getName());
6691
}
6792

6893
} // namespace readability

0 commit comments

Comments
 (0)