Skip to content

Commit 40287bf

Browse files
authored
LLVM and LLVM-SPIRV-Translator pulldown #1656
LLVM: 9142c0b LLVM-SPIRV-Translator: KhronosGroup/SPIRV-LLVM-Translator@8b58a7f
2 parents 212a26c + 3a02d78 commit 40287bf

File tree

2,409 files changed

+88038
-39242
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,409 files changed

+88038
-39242
lines changed

.arclint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"linters": {
33
"clang-format": {
44
"type": "script-and-regex",
5-
"script-and-regex.script": "utils/arcanist/clang-format.sh",
5+
"script-and-regex.script": "bash utils/arcanist/clang-format.sh",
66
"script-and-regex.regex": "/^(?P<severity>[[:alpha:]]+)\n(?P<message>[^\n]+)\n(====|(?P<line>\\d),(?P<char>\\d)\n(?P<original>.*)>>>>\n(?P<replacement>.*)<<<<\n)$/s",
77
"include": [
88
"(\\.(cc|cpp|h)$)"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static std::string getExprAsString(const clang::Expr &E,
7676
Text.erase(
7777
llvm::remove_if(
7878
Text,
79-
[](char C) { return std::isspace(static_cast<unsigned char>(C)); }),
79+
[](char C) { return llvm::isSpace(static_cast<unsigned char>(C)); }),
8080
Text.end());
8181
return Text;
8282
}

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,31 @@ void SignedCharMisuseCheck::registerMatchers(MatchFinder *Finder) {
102102
.bind("comparison");
103103

104104
Finder->addMatcher(CompareOperator, this);
105+
106+
// Catch array subscripts with signed char -> integer conversion.
107+
// Matcher for C arrays.
108+
const auto CArraySubscript =
109+
arraySubscriptExpr(hasIndex(SignedCharCastExpr)).bind("arraySubscript");
110+
111+
Finder->addMatcher(CArraySubscript, this);
112+
113+
// Matcher for std arrays.
114+
const auto STDArraySubscript =
115+
cxxOperatorCallExpr(
116+
hasOverloadedOperatorName("[]"),
117+
hasArgument(0, hasType(cxxRecordDecl(hasName("::std::array")))),
118+
hasArgument(1, SignedCharCastExpr))
119+
.bind("arraySubscript");
120+
121+
Finder->addMatcher(STDArraySubscript, this);
105122
}
106123

107124
void SignedCharMisuseCheck::check(const MatchFinder::MatchResult &Result) {
108125
const auto *SignedCastExpression =
109126
Result.Nodes.getNodeAs<ImplicitCastExpr>("signedCastExpression");
127+
const auto *IntegerType = Result.Nodes.getNodeAs<QualType>("integerType");
128+
assert(SignedCastExpression);
129+
assert(IntegerType);
110130

111131
// Ignore the match if we know that the signed char's value is not negative.
112132
// The potential misinterpretation happens for negative values only.
@@ -135,14 +155,17 @@ void SignedCharMisuseCheck::check(const MatchFinder::MatchResult &Result) {
135155

136156
diag(Comparison->getBeginLoc(),
137157
"comparison between 'signed char' and 'unsigned char'");
138-
} else if (const auto *IntegerType =
139-
Result.Nodes.getNodeAs<QualType>("integerType")) {
158+
} else if (Result.Nodes.getNodeAs<Expr>("arraySubscript")) {
159+
diag(SignedCastExpression->getBeginLoc(),
160+
"'signed char' to %0 conversion in array subscript; "
161+
"consider casting to 'unsigned char' first.")
162+
<< *IntegerType;
163+
} else {
140164
diag(SignedCastExpression->getBeginLoc(),
141165
"'signed char' to %0 conversion; "
142166
"consider casting to 'unsigned char' first.")
143167
<< *IntegerType;
144-
} else
145-
llvm_unreachable("Unexpected match");
168+
}
146169
}
147170

148171
} // namespace bugprone

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS
44
)
55

66
add_clang_library(clangTidyLLVMLibcModule
7+
CalleeNamespaceCheck.cpp
78
ImplementationInNamespaceCheck.cpp
89
LLVMLibcTidyModule.cpp
910
RestrictSystemLibcHeadersCheck.cpp
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//===-- CalleeNamespaceCheck.cpp ------------------------------------------===//
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 "CalleeNamespaceCheck.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 llvm_libc {
18+
19+
// Gets the outermost namespace of a DeclContext, right under the Translation
20+
// Unit.
21+
const DeclContext *getOutermostNamespace(const DeclContext *Decl) {
22+
const DeclContext *Parent = Decl->getParent();
23+
if (Parent && Parent->isTranslationUnit())
24+
return Decl;
25+
return getOutermostNamespace(Parent);
26+
}
27+
28+
void CalleeNamespaceCheck::registerMatchers(MatchFinder *Finder) {
29+
Finder->addMatcher(
30+
declRefExpr(to(functionDecl().bind("func"))).bind("use-site"), this);
31+
}
32+
33+
void CalleeNamespaceCheck::check(const MatchFinder::MatchResult &Result) {
34+
const auto *UsageSiteExpr = Result.Nodes.getNodeAs<DeclRefExpr>("use-site");
35+
const auto *FuncDecl = Result.Nodes.getNodeAs<FunctionDecl>("func");
36+
37+
// Ignore compiler builtin functions.
38+
if (FuncDecl->getBuiltinID() != 0)
39+
return;
40+
41+
// If the outermost namespace of the function is __llvm_libc, we're good.
42+
const auto *NS = dyn_cast<NamespaceDecl>(getOutermostNamespace(FuncDecl));
43+
if (NS && NS->getName() == "__llvm_libc")
44+
return;
45+
46+
diag(UsageSiteExpr->getBeginLoc(), "%0 must resolve to a function declared "
47+
"within the '__llvm_libc' namespace")
48+
<< FuncDecl;
49+
50+
diag(FuncDecl->getLocation(), "resolves to this declaration",
51+
clang::DiagnosticIDs::Note);
52+
}
53+
54+
} // namespace llvm_libc
55+
} // namespace tidy
56+
} // namespace clang
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===-- CalleeNamespaceCheck.h ----------------------------------*- 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_LLVMLIBC_CALLEENAMESPACECHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVMLIBC_CALLEENAMESPACECHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang {
15+
namespace tidy {
16+
namespace llvm_libc {
17+
18+
/// Checks all calls resolve to functions within __llvm_libc namespace.
19+
///
20+
/// For the user-facing documentation see:
21+
/// http://clang.llvm.org/extra/clang-tidy/checks/llvmlibc-callee-namespace.html
22+
class CalleeNamespaceCheck : public ClangTidyCheck {
23+
public:
24+
CalleeNamespaceCheck(StringRef Name, ClangTidyContext *Context)
25+
: ClangTidyCheck(Name, Context) {}
26+
27+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
28+
return LangOpts.CPlusPlus;
29+
}
30+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
31+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
32+
};
33+
34+
} // namespace llvm_libc
35+
} // namespace tidy
36+
} // namespace clang
37+
38+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVMLIBC_CALLEENAMESPACECHECK_H

clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "../ClangTidy.h"
1010
#include "../ClangTidyModule.h"
1111
#include "../ClangTidyModuleRegistry.h"
12+
#include "CalleeNamespaceCheck.h"
1213
#include "ImplementationInNamespaceCheck.h"
1314
#include "RestrictSystemLibcHeadersCheck.h"
1415

@@ -19,6 +20,8 @@ namespace llvm_libc {
1920
class LLVMLibcModule : public ClangTidyModule {
2021
public:
2122
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
23+
CheckFactories.registerCheck<CalleeNamespaceCheck>(
24+
"llvmlibc-callee-namespace");
2225
CheckFactories.registerCheck<ImplementationInNamespaceCheck>(
2326
"llvmlibc-implementation-in-namespace");
2427
CheckFactories.registerCheck<RestrictSystemLibcHeadersCheck>(

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "clang/AST/RecursiveASTVisitor.h"
1313
#include "clang/ASTMatchers/ASTMatchFinder.h"
1414
#include "clang/Tooling/FixIt.h"
15+
#include "llvm/ADT/StringExtras.h"
1516

1617
#include <cctype>
1718

@@ -356,10 +357,10 @@ bool UseTrailingReturnTypeCheck::keepSpecifiers(
356357
unsigned int TOffsetInRT = TOffset - ReturnTypeBeginOffset - DeletedChars;
357358
unsigned int TLengthWithWS = CT.T.getLength();
358359
while (TOffsetInRT + TLengthWithWS < ReturnType.size() &&
359-
std::isspace(ReturnType[TOffsetInRT + TLengthWithWS]))
360+
llvm::isSpace(ReturnType[TOffsetInRT + TLengthWithWS]))
360361
TLengthWithWS++;
361362
std::string Specifier = ReturnType.substr(TOffsetInRT, TLengthWithWS);
362-
if (!std::isspace(Specifier.back()))
363+
if (!llvm::isSpace(Specifier.back()))
363364
Specifier.push_back(' ');
364365
Auto.insert(Auto.size() - InitialAutoLength, Specifier);
365366
ReturnType.erase(TOffsetInRT, TLengthWithWS);
@@ -459,7 +460,7 @@ void UseTrailingReturnTypeCheck::check(const MatchFinder::MatchResult &Result) {
459460
ReturnTypeEnd.getLocWithOffset(1)),
460461
SM, LangOpts);
461462
bool NeedSpaceAfterAuto =
462-
CharAfterReturnType.empty() || !std::isspace(CharAfterReturnType[0]);
463+
CharAfterReturnType.empty() || !llvm::isSpace(CharAfterReturnType[0]);
463464

464465
std::string Auto = NeedSpaceAfterAuto ? "auto " : "auto";
465466
std::string ReturnType =

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ TransformerClangTidyCheck::TransformerClangTidyCheck(
3030
const OptionsView &)>
3131
MakeRule,
3232
StringRef Name, ClangTidyContext *Context)
33-
: ClangTidyCheck(Name, Context), Rule(MakeRule(getLangOpts(), Options)) {
33+
: ClangTidyCheck(Name, Context), Rule(MakeRule(getLangOpts(), Options)),
34+
IncludeStyle(Options.getLocalOrGlobal("IncludeStyle",
35+
IncludeSorter::getMapping(),
36+
IncludeSorter::IS_LLVM)) {
3437
if (Rule)
3538
assert(llvm::all_of(Rule->Cases, hasExplanation) &&
3639
"clang-tidy checks must have an explanation by default;"
@@ -40,7 +43,10 @@ TransformerClangTidyCheck::TransformerClangTidyCheck(
4043
TransformerClangTidyCheck::TransformerClangTidyCheck(RewriteRule R,
4144
StringRef Name,
4245
ClangTidyContext *Context)
43-
: ClangTidyCheck(Name, Context), Rule(std::move(R)) {
46+
: ClangTidyCheck(Name, Context), Rule(std::move(R)),
47+
IncludeStyle(Options.getLocalOrGlobal("IncludeStyle",
48+
IncludeSorter::getMapping(),
49+
IncludeSorter::IS_LLVM)) {
4450
assert(llvm::all_of(Rule->Cases, hasExplanation) &&
4551
"clang-tidy checks must have an explanation by default;"
4652
" explicitly provide an empty explanation if none is desired");
@@ -53,8 +59,8 @@ void TransformerClangTidyCheck::registerPPCallbacks(
5359
if (Rule && llvm::any_of(Rule->Cases, [](const RewriteRule::Case &C) {
5460
return !C.AddedIncludes.empty();
5561
})) {
56-
Inserter = std::make_unique<IncludeInserter>(
57-
SM, getLangOpts(), utils::IncludeSorter::IS_LLVM);
62+
Inserter =
63+
std::make_unique<IncludeInserter>(SM, getLangOpts(), IncludeStyle);
5864
PP->addPPCallbacks(Inserter->CreatePPCallbacks());
5965
}
6066
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_TRANSFORMER_CLANG_TIDY_CHECK_H
1111

1212
#include "../ClangTidy.h"
13-
#include "../utils/IncludeInserter.h"
13+
#include "IncludeInserter.h"
14+
#include "IncludeSorter.h"
1415
#include "clang/ASTMatchers/ASTMatchFinder.h"
1516
#include "clang/Frontend/CompilerInstance.h"
1617
#include "clang/Tooling/Transformer/Transformer.h"
@@ -31,6 +32,13 @@ namespace utils {
3132
// MyCheck(StringRef Name, ClangTidyContext *Context)
3233
// : TransformerClangTidyCheck(MyCheckAsRewriteRule, Name, Context) {}
3334
// };
35+
//
36+
// `TransformerClangTidyCheck` recognizes this clang-tidy option:
37+
//
38+
// * IncludeStyle. A string specifying which file naming convention is used by
39+
// the source code, 'llvm' or 'google'. Default is 'llvm'. The naming
40+
// convention influences how canonical headers are distinguished from other
41+
// includes.
3442
class TransformerClangTidyCheck : public ClangTidyCheck {
3543
public:
3644
// \p MakeRule generates the rewrite rule to be used by the check, based on
@@ -61,7 +69,8 @@ class TransformerClangTidyCheck : public ClangTidyCheck {
6169

6270
private:
6371
Optional<transformer::RewriteRule> Rule;
64-
std::unique_ptr<clang::tidy::utils::IncludeInserter> Inserter;
72+
const IncludeSorter::IncludeStyle IncludeStyle;
73+
std::unique_ptr<IncludeInserter> Inserter;
6574
};
6675

6776
} // namespace utils

clang-tools-extra/clangd/CMakeLists.txt

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
add_subdirectory(support)
2+
13
# Configure the Features.inc file.
24
if (NOT DEFINED CLANGD_BUILD_XPC)
35
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
@@ -25,27 +27,15 @@ set(LLVM_LINK_COMPONENTS
2527
FrontendOpenMP
2628
)
2729

28-
if(CLANG_BUILT_STANDALONE)
29-
# needed to get HAVE_CXX_ATOMICS64_WITHOUT_LIB defined
30-
include(CheckAtomic)
31-
endif()
32-
33-
set(CLANGD_ATOMIC_LIB "")
34-
if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB OR NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
35-
list(APPEND CLANGD_ATOMIC_LIB "atomic")
36-
endif()
37-
3830
add_clang_library(clangDaemon
3931
AST.cpp
40-
Cancellation.cpp
4132
ClangdLSPServer.cpp
4233
ClangdServer.cpp
4334
CodeComplete.cpp
4435
CodeCompletionStrings.cpp
4536
CollectMacros.cpp
4637
CompileCommands.cpp
4738
Compiler.cpp
48-
Context.cpp
4939
Diagnostics.cpp
5040
DraftStore.cpp
5141
ExpectedTypes.cpp
@@ -54,16 +44,13 @@ add_clang_library(clangDaemon
5444
FileDistance.cpp
5545
Format.cpp
5646
FS.cpp
57-
FSProvider.cpp
58-
FormattedString.cpp
5947
FuzzyMatch.cpp
6048
GlobalCompilationDatabase.cpp
6149
Headers.cpp
6250
HeaderSourceSwitch.cpp
6351
Hover.cpp
6452
IncludeFixer.cpp
6553
JSONTransport.cpp
66-
Logger.cpp
6754
PathMapping.cpp
6855
Protocol.cpp
6956
Quality.cpp
@@ -73,11 +60,8 @@ add_clang_library(clangDaemon
7360
Selection.cpp
7461
SemanticHighlighting.cpp
7562
SemanticSelection.cpp
76-
Shutdown.cpp
7763
SourceCode.cpp
7864
QueryDriverDatabase.cpp
79-
Threading.cpp
80-
Trace.cpp
8165
TUScheduler.cpp
8266
URI.cpp
8367
XRefs.cpp
@@ -128,8 +112,8 @@ add_clang_library(clangDaemon
128112
clangToolingInclusions
129113
clangToolingRefactoring
130114
clangToolingSyntax
115+
clangdSupport
131116
${LLVM_PTHREAD_LIB}
132-
${CLANGD_ATOMIC_LIB}
133117
${ALL_CLANG_TIDY_CHECKS}
134118
)
135119

0 commit comments

Comments
 (0)