Skip to content

Commit 501acc6

Browse files
authored
SPIRV-LLVM-Translator pulldown (WW39) #4612
LLVM: llvm/llvm-project@6cd382b SPIRV-LLVM-Translator: KhronosGroup/SPIRV-LLVM-Translator@20bcfe8
2 parents 42c6f44 + ff2d235 commit 501acc6

File tree

2,031 files changed

+98401
-299757
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,031 files changed

+98401
-299757
lines changed

clang-tools-extra/clang-include-fixer/IncludeFixer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ clang::TypoCorrection IncludeFixerSemaSource::CorrectTypo(
245245
// parent_path.
246246
// FIXME: Don't rely on source text.
247247
const char *End = Source.end();
248-
while (isIdentifierBody(*End) || *End == ':')
248+
while (isAsciiIdentifierContinue(*End) || *End == ':')
249249
++End;
250250

251251
return std::string(Source.begin(), End);

clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void IntegerTypesCheck::check(const MatchFinder::MatchResult &Result) {
129129
const StringRef Port = "unsigned short port";
130130
const char *Data = Result.SourceManager->getCharacterData(Loc);
131131
if (!std::strncmp(Data, Port.data(), Port.size()) &&
132-
!isIdentifierBody(Data[Port.size()]))
132+
!isAsciiIdentifierContinue(Data[Port.size()]))
133133
return;
134134

135135
std::string Replacement =

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_clang_library(clangTidyReadabilityModule
77
AvoidConstParamsInDecls.cpp
88
BracesAroundStatementsCheck.cpp
99
ConstReturnTypeCheck.cpp
10+
ContainerDataPointerCheck.cpp
1011
ContainerSizeEmptyCheck.cpp
1112
ConvertMemberFunctionsToStatic.cpp
1213
DeleteNullPointerCheck.cpp
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
//===--- ContainerDataPointerCheck.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 "ContainerDataPointerCheck.h"
10+
11+
#include "clang/Lex/Lexer.h"
12+
#include "llvm/ADT/StringRef.h"
13+
14+
using namespace clang::ast_matchers;
15+
16+
namespace clang {
17+
namespace tidy {
18+
namespace readability {
19+
ContainerDataPointerCheck::ContainerDataPointerCheck(StringRef Name,
20+
ClangTidyContext *Context)
21+
: ClangTidyCheck(Name, Context) {}
22+
23+
void ContainerDataPointerCheck::registerMatchers(MatchFinder *Finder) {
24+
const auto Record =
25+
cxxRecordDecl(
26+
isSameOrDerivedFrom(
27+
namedDecl(
28+
has(cxxMethodDecl(isPublic(), hasName("data")).bind("data")))
29+
.bind("container")))
30+
.bind("record");
31+
32+
const auto NonTemplateContainerType =
33+
qualType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(Record))));
34+
const auto TemplateContainerType =
35+
qualType(hasUnqualifiedDesugaredType(templateSpecializationType(
36+
hasDeclaration(classTemplateDecl(has(Record))))));
37+
38+
const auto Container =
39+
qualType(anyOf(NonTemplateContainerType, TemplateContainerType));
40+
41+
Finder->addMatcher(
42+
unaryOperator(
43+
unless(isExpansionInSystemHeader()), hasOperatorName("&"),
44+
hasUnaryOperand(anyOf(
45+
ignoringParenImpCasts(
46+
cxxOperatorCallExpr(
47+
callee(cxxMethodDecl(hasName("operator[]"))
48+
.bind("operator[]")),
49+
argumentCountIs(2),
50+
hasArgument(
51+
0,
52+
anyOf(ignoringParenImpCasts(
53+
declRefExpr(
54+
to(varDecl(anyOf(
55+
hasType(Container),
56+
hasType(references(Container))))))
57+
.bind("var")),
58+
ignoringParenImpCasts(hasDescendant(
59+
declRefExpr(
60+
to(varDecl(anyOf(
61+
hasType(Container),
62+
hasType(pointsTo(Container)),
63+
hasType(references(Container))))))
64+
.bind("var"))))),
65+
hasArgument(1,
66+
ignoringParenImpCasts(
67+
integerLiteral(equals(0)).bind("zero"))))
68+
.bind("operator-call")),
69+
ignoringParenImpCasts(
70+
cxxMemberCallExpr(
71+
hasDescendant(
72+
declRefExpr(to(varDecl(anyOf(
73+
hasType(Container),
74+
hasType(references(Container))))))
75+
.bind("var")),
76+
argumentCountIs(1),
77+
hasArgument(0,
78+
ignoringParenImpCasts(
79+
integerLiteral(equals(0)).bind("zero"))))
80+
.bind("member-call")),
81+
ignoringParenImpCasts(
82+
arraySubscriptExpr(
83+
hasLHS(ignoringParenImpCasts(
84+
declRefExpr(to(varDecl(anyOf(
85+
hasType(Container),
86+
hasType(references(Container))))))
87+
.bind("var"))),
88+
hasRHS(ignoringParenImpCasts(
89+
integerLiteral(equals(0)).bind("zero"))))
90+
.bind("array-subscript")))))
91+
.bind("address-of"),
92+
this);
93+
}
94+
95+
void ContainerDataPointerCheck::check(const MatchFinder::MatchResult &Result) {
96+
const auto *UO = Result.Nodes.getNodeAs<UnaryOperator>("address-of");
97+
const auto *DRE = Result.Nodes.getNodeAs<DeclRefExpr>("var");
98+
99+
std::string ReplacementText;
100+
ReplacementText = std::string(Lexer::getSourceText(
101+
CharSourceRange::getTokenRange(DRE->getSourceRange()),
102+
*Result.SourceManager, getLangOpts()));
103+
if (DRE->getType()->isPointerType())
104+
ReplacementText += "->data()";
105+
else
106+
ReplacementText += ".data()";
107+
108+
FixItHint Hint =
109+
FixItHint::CreateReplacement(UO->getSourceRange(), ReplacementText);
110+
diag(UO->getBeginLoc(),
111+
"'data' should be used for accessing the data pointer instead of taking "
112+
"the address of the 0-th element")
113+
<< Hint;
114+
}
115+
} // namespace readability
116+
} // namespace tidy
117+
} // namespace clang
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//===--- ContainerDataPointerCheck.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_READABILITY_CONTAINERDATAPOINTERCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONTAINERDATAPOINTERCHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang {
15+
namespace tidy {
16+
namespace readability {
17+
/// Checks whether a call to `operator[]` and `&` can be replaced with a call to
18+
/// `data()`.
19+
///
20+
/// This only replaces the case where the offset being accessed through the
21+
/// subscript operation is a known constant 0. This avoids a potential invalid
22+
/// memory access when the container is empty. Cases where the constant is not
23+
/// explictly zero can be addressed through the clang static analyzer, and those
24+
/// which cannot be statically identified can be caught using UBSan.
25+
class ContainerDataPointerCheck : public ClangTidyCheck {
26+
public:
27+
ContainerDataPointerCheck(StringRef Name, ClangTidyContext *Context);
28+
29+
bool isLanguageVersionSupported(const LangOptions &LO) const override {
30+
return LO.CPlusPlus11;
31+
}
32+
33+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
34+
35+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
36+
37+
llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
38+
return TK_IgnoreUnlessSpelledInSource;
39+
}
40+
};
41+
} // namespace readability
42+
} // namespace tidy
43+
} // namespace clang
44+
45+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_CONTAINERDATAPOINTERCHECK_H

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "AvoidConstParamsInDecls.h"
1313
#include "BracesAroundStatementsCheck.h"
1414
#include "ConstReturnTypeCheck.h"
15+
#include "ContainerDataPointerCheck.h"
1516
#include "ContainerSizeEmptyCheck.h"
1617
#include "ConvertMemberFunctionsToStatic.h"
1718
#include "DeleteNullPointerCheck.h"
@@ -62,6 +63,8 @@ class ReadabilityModule : public ClangTidyModule {
6263
"readability-braces-around-statements");
6364
CheckFactories.registerCheck<ConstReturnTypeCheck>(
6465
"readability-const-return-type");
66+
CheckFactories.registerCheck<ContainerDataPointerCheck>(
67+
"readability-container-data-pointer");
6568
CheckFactories.registerCheck<ContainerSizeEmptyCheck>(
6669
"readability-container-size-empty");
6770
CheckFactories.registerCheck<ConvertMemberFunctionsToStatic>(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ void RenamerClangTidyCheck::check(const MatchFinder::MatchResult &Result) {
464464
Failure.FixStatus = ShouldFixStatus::ConflictsWithKeyword;
465465
else if (Ident->hasMacroDefinition())
466466
Failure.FixStatus = ShouldFixStatus::ConflictsWithMacroDefinition;
467-
} else if (!isValidIdentifier(Info.Fixup)) {
467+
} else if (!isValidAsciiIdentifier(Info.Fixup)) {
468468
Failure.FixStatus = ShouldFixStatus::FixInvalidIdentifier;
469469
}
470470

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,14 +1842,14 @@ CompletionPrefix guessCompletionPrefix(llvm::StringRef Content,
18421842
CompletionPrefix Result;
18431843

18441844
// Consume the unqualified name. We only handle ASCII characters.
1845-
// isIdentifierBody will let us match "0invalid", but we don't mind.
1846-
while (!Rest.empty() && isIdentifierBody(Rest.back()))
1845+
// isAsciiIdentifierContinue will let us match "0invalid", but we don't mind.
1846+
while (!Rest.empty() && isAsciiIdentifierContinue(Rest.back()))
18471847
Rest = Rest.drop_back();
18481848
Result.Name = Content.slice(Rest.size(), Offset);
18491849

18501850
// Consume qualifiers.
18511851
while (Rest.consume_back("::") && !Rest.endswith(":")) // reject ::::
1852-
while (!Rest.empty() && isIdentifierBody(Rest.back()))
1852+
while (!Rest.empty() && isAsciiIdentifierContinue(Rest.back()))
18531853
Rest = Rest.drop_back();
18541854
Result.Qualifier =
18551855
Content.slice(Rest.size(), Result.Name.begin() - Content.begin());
@@ -1874,9 +1874,10 @@ CodeCompleteResult codeComplete(PathRef FileName, Position Pos,
18741874
? std::move(Flow).runWithoutSema(ParseInput.Contents, *Offset,
18751875
*ParseInput.TFS)
18761876
: std::move(Flow).run({FileName, *Offset, *Preamble,
1877-
// We want to serve code completions with
1878-
// low latency, so don't bother patching.
1879-
/*PreamblePatch=*/llvm::None, ParseInput});
1877+
/*PreamblePatch=*/
1878+
PreamblePatch::createMacroPatch(
1879+
FileName, ParseInput, *Preamble),
1880+
ParseInput});
18801881
}
18811882

18821883
SignatureHelp signatureHelp(PathRef FileName, Position Pos,
@@ -1898,7 +1899,8 @@ SignatureHelp signatureHelp(PathRef FileName, Position Pos,
18981899
Result),
18991900
Options,
19001901
{FileName, *Offset, Preamble,
1901-
PreamblePatch::create(FileName, ParseInput, Preamble), ParseInput});
1902+
PreamblePatch::createFullPatch(FileName, ParseInput, Preamble),
1903+
ParseInput});
19021904
return Result;
19031905
}
19041906

@@ -2057,8 +2059,8 @@ bool allowImplicitCompletion(llvm::StringRef Content, unsigned Offset) {
20572059
return true;
20582060

20592061
// Complete words. Give non-ascii characters the benefit of the doubt.
2060-
return !Content.empty() &&
2061-
(isIdentifierBody(Content.back()) || !llvm::isASCII(Content.back()));
2062+
return !Content.empty() && (isAsciiIdentifierContinue(Content.back()) ||
2063+
!llvm::isASCII(Content.back()));
20622064
}
20632065

20642066
} // namespace clangd

clang-tools-extra/clangd/CompileCommands.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,22 +198,26 @@ CommandMangler CommandMangler::forTests() { return CommandMangler(); }
198198
void CommandMangler::adjust(std::vector<std::string> &Cmd,
199199
llvm::StringRef File) const {
200200
trace::Span S("AdjustCompileFlags");
201+
// Most of the modifications below assumes the Cmd starts with a driver name.
202+
// We might consider injecting a generic driver name like "cc" or "c++", but
203+
// a Cmd missing the driver is probably rare enough in practice and errnous.
204+
if (Cmd.empty())
205+
return;
201206
auto &OptTable = clang::driver::getDriverOptTable();
202207
// OriginalArgs needs to outlive ArgList.
203208
llvm::SmallVector<const char *, 16> OriginalArgs;
204209
OriginalArgs.reserve(Cmd.size());
205210
for (const auto &S : Cmd)
206211
OriginalArgs.push_back(S.c_str());
207-
bool IsCLMode =
208-
!OriginalArgs.empty() &&
209-
driver::IsClangCL(driver::getDriverMode(
210-
OriginalArgs[0], llvm::makeArrayRef(OriginalArgs).slice(1)));
212+
bool IsCLMode = driver::IsClangCL(driver::getDriverMode(
213+
OriginalArgs[0], llvm::makeArrayRef(OriginalArgs).slice(1)));
211214
// ParseArgs propagates missig arg/opt counts on error, but preserves
212215
// everything it could parse in ArgList. So we just ignore those counts.
213216
unsigned IgnoredCount;
214217
// Drop the executable name, as ParseArgs doesn't expect it. This means
215218
// indices are actually of by one between ArgList and OriginalArgs.
216-
auto ArgList = OptTable.ParseArgs(
219+
llvm::opt::InputArgList ArgList;
220+
ArgList = OptTable.ParseArgs(
217221
llvm::makeArrayRef(OriginalArgs).drop_front(), IgnoredCount, IgnoredCount,
218222
/*FlagsToInclude=*/
219223
IsCLMode ? (driver::options::CLOption | driver::options::CoreOption)

clang-tools-extra/clangd/Compiler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ void disableUnsupportedOptions(CompilerInvocation &CI) {
8383
std::unique_ptr<CompilerInvocation>
8484
buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
8585
std::vector<std::string> *CC1Args) {
86+
if (Inputs.CompileCommand.CommandLine.empty())
87+
return nullptr;
8688
std::vector<const char *> ArgStrs;
8789
for (const auto &S : Inputs.CompileCommand.CommandLine)
8890
ArgStrs.push_back(S.c_str());

clang-tools-extra/clangd/FindTarget.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ const NamedDecl *getTemplatePattern(const NamedDecl *D) {
9494
return nullptr;
9595
}
9696

97+
// Returns true if the `TypedefNameDecl` should not be reported.
98+
bool shouldSkipTypedef(const TypedefNameDecl *TD) {
99+
// These should be treated as keywords rather than decls - the typedef is an
100+
// odd implementation detail.
101+
if (TD == TD->getASTContext().getObjCInstanceTypeDecl() ||
102+
TD == TD->getASTContext().getObjCIdDecl())
103+
return true;
104+
return false;
105+
}
106+
97107
// TargetFinder locates the entities that an AST node refers to.
98108
//
99109
// Typically this is (possibly) one declaration and (possibly) one type, but
@@ -395,6 +405,8 @@ struct TargetFinder {
395405
}
396406
}
397407
void VisitTypedefType(const TypedefType *TT) {
408+
if (shouldSkipTypedef(TT->getDecl()))
409+
return;
398410
Outer.add(TT->getDecl(), Flags);
399411
}
400412
void
@@ -903,6 +915,8 @@ refInTypeLoc(TypeLoc L, const HeuristicResolver *Resolver) {
903915
}
904916

905917
void VisitTypedefTypeLoc(TypedefTypeLoc L) {
918+
if (shouldSkipTypedef(L.getTypedefNameDecl()))
919+
return;
906920
Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
907921
L.getNameLoc(),
908922
/*IsDecl=*/false,

0 commit comments

Comments
 (0)