Skip to content

Commit 1d8ceba

Browse files
committed
LLVM and SPIRV-LLVM-Translator pulldown (WW45)
LLVM: llvm/llvm-project@cf78715
2 parents 53ea8b9 + 4281da1 commit 1d8ceba

File tree

2,382 files changed

+102149
-58109
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,382 files changed

+102149
-58109
lines changed

.github/workflows/repo-lockdown.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ permissions:
99
jobs:
1010
action:
1111
runs-on: ubuntu-latest
12+
if: github.repository == 'llvm/llvm-project'
1213
steps:
1314
- uses: dessant/repo-lockdown@v2
1415
with:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static const std::string DefaultIgnoredParameterTypeSuffixes =
4040
"inputit",
4141
"InputIt",
4242
"forwardit",
43-
"FowardIt",
43+
"ForwardIt",
4444
"bidirit",
4545
"BidirIt",
4646
"constiterator",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void ForwardDeclarationNamespaceCheck::onEndOfTranslationUnit() {
123123
if (CurDecl->hasDefinition() || CurDecl->isReferenced()) {
124124
continue; // Skip forward declarations that are used/referenced.
125125
}
126-
if (FriendTypes.count(CurDecl->getTypeForDecl()) != 0) {
126+
if (FriendTypes.contains(CurDecl->getTypeForDecl())) {
127127
continue; // Skip forward declarations referenced as friend.
128128
}
129129
if (CurDecl->getLocation().isMacroID() ||

clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ computeInsertions(const CXXConstructorDecl::init_const_range &Inits,
209209
// Add all fields between current field up until the next initializer.
210210
for (; Decl != std::end(OrderedDecls) && *Decl != InitDecl; ++Decl) {
211211
if (const auto *D = dyn_cast<T>(*Decl)) {
212-
if (DeclsToInit.count(D) > 0)
212+
if (DeclsToInit.contains(D))
213213
Insertions.back().Initializers.emplace_back(getName(D));
214214
}
215215
}
@@ -221,7 +221,7 @@ computeInsertions(const CXXConstructorDecl::init_const_range &Inits,
221221
// Add remaining decls that require initialization.
222222
for (; Decl != std::end(OrderedDecls); ++Decl) {
223223
if (const auto *D = dyn_cast<T>(*Decl)) {
224-
if (DeclsToInit.count(D) > 0)
224+
if (DeclsToInit.contains(D))
225225
Insertions.back().Initializers.emplace_back(getName(D));
226226
}
227227
}

clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ void UnusedUsingDeclsCheck::removeFromFoundDecls(const Decl *D) {
172172
//
173173
// FIXME: Use a more efficient way to find a matching context.
174174
for (auto &Context : Contexts) {
175-
if (Context.UsingTargetDecls.count(D->getCanonicalDecl()) > 0)
175+
if (Context.UsingTargetDecls.contains(D->getCanonicalDecl()))
176176
Context.IsUsed = true;
177177
}
178178
}

clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ AST_MATCHER_FUNCTION_P(StatementMatcher, isConstRefReturningMethodCall,
8484
// returned either points to a global static variable or to a member of the
8585
// called object.
8686
return cxxMemberCallExpr(
87-
callee(cxxMethodDecl(returns(matchers::isReferenceToConst()))
87+
callee(cxxMethodDecl(
88+
returns(hasCanonicalType(matchers::isReferenceToConst())))
8889
.bind(MethodDeclId)),
8990
on(declRefExpr(to(
9091
varDecl(
@@ -97,7 +98,8 @@ AST_MATCHER_FUNCTION(StatementMatcher, isConstRefReturningFunctionCall) {
9798
// Only allow initialization of a const reference from a free function if it
9899
// has no arguments. Otherwise it could return an alias to one of its
99100
// arguments and the arguments need to be checked for const use as well.
100-
return callExpr(callee(functionDecl(returns(matchers::isReferenceToConst()))
101+
return callExpr(callee(functionDecl(returns(hasCanonicalType(
102+
matchers::isReferenceToConst())))
101103
.bind(FunctionDeclId)),
102104
argumentCountIs(0), unless(callee(cxxMethodDecl())))
103105
.bind(InitFunctionCallId);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ void InconsistentDeclarationParameterNameCheck::check(
303303
const auto *OriginalDeclaration =
304304
Result.Nodes.getNodeAs<FunctionDecl>("functionDecl");
305305

306-
if (VisitedDeclarations.count(OriginalDeclaration) > 0)
306+
if (VisitedDeclarations.contains(OriginalDeclaration))
307307
return; // Avoid multiple warnings.
308308

309309
const FunctionDecl *ParameterSourceDeclaration =

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "StaticAccessedThroughInstanceCheck.h"
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
#include "llvm/ADT/StringRef.h"
1213

1314
using namespace clang::ast_matchers;
1415

@@ -54,7 +55,7 @@ void StaticAccessedThroughInstanceCheck::check(
5455

5556
const Expr *BaseExpr = MemberExpression->getBase();
5657

57-
// Do not warn for overlaoded -> operators.
58+
// Do not warn for overloaded -> operators.
5859
if (isa<CXXOperatorCallExpr>(BaseExpr))
5960
return;
6061

@@ -70,6 +71,10 @@ void StaticAccessedThroughInstanceCheck::check(
7071
std::string BaseTypeName =
7172
BaseType.getAsString(PrintingPolicyWithSupressedTag);
7273

74+
// Do not warn for CUDA built-in variables.
75+
if (StringRef(BaseTypeName).startswith("__cuda_builtin_"))
76+
return;
77+
7378
SourceLocation MemberExprStartLoc = MemberExpression->getBeginLoc();
7479
auto Diag =
7580
diag(MemberExprStartLoc, "static member accessed through instance");

clang-tools-extra/clangd/Compiler.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ void IgnoreDiagnostics::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
4242
IgnoreDiagnostics::log(DiagLevel, Info);
4343
}
4444

45+
static bool AllowCrashPragmasForTest = false;
46+
void allowCrashPragmasForTest() { AllowCrashPragmasForTest = true; }
47+
4548
void disableUnsupportedOptions(CompilerInvocation &CI) {
4649
// Disable "clang -verify" diagnostics, they are rarely useful in clangd, and
4750
// our compiler invocation set-up doesn't seem to work with it (leading
@@ -66,7 +69,8 @@ void disableUnsupportedOptions(CompilerInvocation &CI) {
6669
CI.getPreprocessorOpts().PCHWithHdrStop = false;
6770
CI.getPreprocessorOpts().PCHWithHdrStopCreate = false;
6871
// Don't crash on `#pragma clang __debug parser_crash`
69-
CI.getPreprocessorOpts().DisablePragmaDebugCrash = true;
72+
if (!AllowCrashPragmasForTest)
73+
CI.getPreprocessorOpts().DisablePragmaDebugCrash = true;
7074

7175
// Always default to raw container format as clangd doesn't registry any other
7276
// and clang dies when faced with unknown formats.

clang-tools-extra/clangd/Compiler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ std::unique_ptr<CompilerInstance> prepareCompilerInstance(
8787
std::unique_ptr<llvm::MemoryBuffer> MainFile,
8888
IntrusiveRefCntPtr<llvm::vfs::FileSystem>, DiagnosticConsumer &);
8989

90+
/// Respect `#pragma clang __debug crash` etc, which are usually disabled.
91+
/// This may only be called before threads are spawned.
92+
void allowCrashPragmasForTest();
93+
9094
} // namespace clangd
9195
} // namespace clang
9296

clang-tools-extra/clangd/Config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct Config {
8686
ExternalIndexSpec External;
8787
} Index;
8888

89+
enum UnusedIncludesPolicy { Strict, None };
8990
/// Controls warnings and errors when parsing code.
9091
struct {
9192
bool SuppressAll = false;
@@ -97,6 +98,8 @@ struct Config {
9798
std::string Checks;
9899
llvm::StringMap<std::string> CheckOptions;
99100
} ClangTidy;
101+
102+
UnusedIncludesPolicy UnusedIncludes = None;
100103
} Diagnostics;
101104

102105
/// Style of the codebase.

clang-tools-extra/clangd/ConfigCompile.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,16 @@ struct FragmentCompiler {
414414
C.Diagnostics.Suppress.insert(N);
415415
});
416416

417+
if (F.UnusedIncludes)
418+
if (auto Val = compileEnum<Config::UnusedIncludesPolicy>(
419+
"UnusedIncludes", **F.UnusedIncludes)
420+
.map("Strict", Config::UnusedIncludesPolicy::Strict)
421+
.map("None", Config::UnusedIncludesPolicy::None)
422+
.value())
423+
Out.Apply.push_back([Val](const Params &, Config &C) {
424+
C.Diagnostics.UnusedIncludes = *Val;
425+
});
426+
417427
compile(std::move(F.ClangTidy));
418428
}
419429

clang-tools-extra/clangd/ConfigFragment.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,20 @@ struct Fragment {
210210
/// This often has other advantages, such as skipping some analysis.
211211
std::vector<Located<std::string>> Suppress;
212212

213+
/// Controls how clangd will correct "unnecessary #include directives.
214+
/// clangd can warn if a header is `#include`d but not used, and suggest
215+
/// removing it.
216+
//
217+
/// Strict means a header is unused if it does not *directly* provide any
218+
/// symbol used in the file. Removing it may still break compilation if it
219+
/// transitively includes headers that are used. This should be fixed by
220+
/// including those headers directly.
221+
///
222+
/// Valid values are:
223+
/// - Strict
224+
/// - None
225+
llvm::Optional<Located<std::string>> UnusedIncludes;
226+
213227
/// Controls how clang-tidy will run over the code base.
214228
///
215229
/// The settings are merged with any settings found in .clang-tidy

clang-tools-extra/clangd/ConfigYAML.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ class Parser {
118118
if (auto Values = scalarValues(N))
119119
F.Suppress = std::move(*Values);
120120
});
121+
Dict.handle("UnusedIncludes", [&](Node &N) {
122+
F.UnusedIncludes = scalarValue(N, "UnusedIncludes");
123+
});
121124
Dict.handle("ClangTidy", [&](Node &N) { parse(F.ClangTidy, N); });
122125
Dict.parse(N);
123126
}

clang-tools-extra/clangd/Diagnostics.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,9 @@ void toLSPDiags(
485485
case Diag::ClangTidy:
486486
Main.source = "clang-tidy";
487487
break;
488+
case Diag::Clangd:
489+
Main.source = "clangd";
490+
break;
488491
case Diag::ClangdConfig:
489492
Main.source = "clangd-config";
490493
break;

clang-tools-extra/clangd/Diagnostics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ struct Diag : DiagBase {
101101
Unknown,
102102
Clang,
103103
ClangTidy,
104+
Clangd,
104105
ClangdConfig,
105106
} Source = Unknown;
106107
/// Elaborate on the problem, usually pointing to a related piece of code.

clang-tools-extra/clangd/Hover.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -262,24 +262,30 @@ const FunctionDecl *getUnderlyingFunction(const Decl *D) {
262262
// Returns the decl that should be used for querying comments, either from index
263263
// or AST.
264264
const NamedDecl *getDeclForComment(const NamedDecl *D) {
265+
const NamedDecl *DeclForComment = D;
265266
if (const auto *TSD = llvm::dyn_cast<ClassTemplateSpecializationDecl>(D)) {
266267
// Template may not be instantiated e.g. if the type didn't need to be
267268
// complete; fallback to primary template.
268269
if (TSD->getTemplateSpecializationKind() == TSK_Undeclared)
269-
return TSD->getSpecializedTemplate();
270-
if (const auto *TIP = TSD->getTemplateInstantiationPattern())
271-
return TIP;
272-
}
273-
if (const auto *TSD = llvm::dyn_cast<VarTemplateSpecializationDecl>(D)) {
270+
DeclForComment = TSD->getSpecializedTemplate();
271+
else if (const auto *TIP = TSD->getTemplateInstantiationPattern())
272+
DeclForComment = TIP;
273+
} else if (const auto *TSD =
274+
llvm::dyn_cast<VarTemplateSpecializationDecl>(D)) {
274275
if (TSD->getTemplateSpecializationKind() == TSK_Undeclared)
275-
return TSD->getSpecializedTemplate();
276-
if (const auto *TIP = TSD->getTemplateInstantiationPattern())
277-
return TIP;
278-
}
279-
if (const auto *FD = D->getAsFunction())
276+
DeclForComment = TSD->getSpecializedTemplate();
277+
else if (const auto *TIP = TSD->getTemplateInstantiationPattern())
278+
DeclForComment = TIP;
279+
} else if (const auto *FD = D->getAsFunction())
280280
if (const auto *TIP = FD->getTemplateInstantiationPattern())
281-
return TIP;
282-
return D;
281+
DeclForComment = TIP;
282+
// Ensure that getDeclForComment(getDeclForComment(X)) = getDeclForComment(X).
283+
// This is usually not needed, but in strange cases of comparision operators
284+
// being instantiated from spasceship operater, which itself is a template
285+
// instantiation the recursrive call is necessary.
286+
if (D != DeclForComment)
287+
DeclForComment = getDeclForComment(DeclForComment);
288+
return DeclForComment;
283289
}
284290

285291
// Look up information about D from the index, and add it to Hover.

0 commit comments

Comments
 (0)