Skip to content

Commit a4d4cfb

Browse files
authored
LLVM and SPIRV-LLVM-Translator pulldown (WW03-04)
LLVM: llvm/llvm-project@35c9baa SPIRV-LLVM-Translator: KhronosGroup/SPIRV-LLVM-Translator@5d678fe
2 parents 2ba8e05 + 3dbf62a commit a4d4cfb

File tree

5,040 files changed

+205073
-67701
lines changed

Some content is hidden

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

5,040 files changed

+205073
-67701
lines changed

clang-tools-extra/clang-tidy/ClangTidyOptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ parseConfiguration(llvm::MemoryBufferRef Config) {
392392

393393
static void diagHandlerImpl(const llvm::SMDiagnostic &Diag, void *Ctx) {
394394
(*reinterpret_cast<DiagCallback *>(Ctx))(Diag);
395-
};
395+
}
396396

397397
llvm::ErrorOr<ClangTidyOptions>
398398
parseConfigurationWithDiags(llvm::MemoryBufferRef Config,

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

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ namespace clang {
2424
namespace tidy {
2525
namespace abseil {
2626

27+
using ::clang::transformer::addInclude;
2728
using ::clang::transformer::applyFirst;
2829
using ::clang::transformer::cat;
29-
using ::clang::transformer::change;
30+
using ::clang::transformer::changeTo;
3031
using ::clang::transformer::makeRule;
3132
using ::clang::transformer::node;
3233
using ::clang::transformer::RewriteRule;
@@ -38,22 +39,9 @@ static const char DefaultStringLikeClasses[] = "::std::basic_string;"
3839
"::absl::string_view";
3940
static const char DefaultAbseilStringsMatchHeader[] = "absl/strings/match.h";
4041

41-
static llvm::Optional<transformer::RewriteRule>
42-
MakeRule(const LangOptions &LangOpts,
43-
const ClangTidyCheck::OptionsView &Options) {
44-
// Parse options.
45-
//
46-
// FIXME(tdl-g): These options are being parsed redundantly with the
47-
// constructor because TransformerClangTidyCheck forces us to provide MakeRule
48-
// before "this" is fully constructed, but StoreOptions requires us to store
49-
// the parsed options in "this". We need to fix TransformerClangTidyCheck and
50-
// then we can clean this up.
51-
const std::vector<std::string> StringLikeClassNames =
52-
utils::options::parseStringList(
53-
Options.get("StringLikeClasses", DefaultStringLikeClasses));
54-
const std::string AbseilStringsMatchHeader =
55-
Options.get("AbseilStringsMatchHeader", DefaultAbseilStringsMatchHeader);
56-
42+
static transformer::RewriteRule
43+
makeRewriteRule(const std::vector<std::string> &StringLikeClassNames,
44+
StringRef AbseilStringsMatchHeader) {
5745
auto StringLikeClass = cxxRecordDecl(hasAnyName(SmallVector<StringRef, 4>(
5846
StringLikeClassNames.begin(), StringLikeClassNames.end())));
5947
auto StringType =
@@ -75,29 +63,36 @@ MakeRule(const LangOptions &LangOpts,
7563
onImplicitObjectArgument(expr().bind("string_being_searched")));
7664

7765
RewriteRule rule = applyFirst(
78-
{makeRule(binaryOperator(hasOperatorName("=="),
79-
hasOperands(ignoringParenImpCasts(StringNpos),
80-
ignoringParenImpCasts(StringFind))),
81-
change(cat("!absl::StrContains(", node("string_being_searched"),
82-
", ", node("parameter_to_find"), ")")),
83-
cat("use !absl::StrContains instead of find() == npos")),
84-
makeRule(binaryOperator(hasOperatorName("!="),
85-
hasOperands(ignoringParenImpCasts(StringNpos),
86-
ignoringParenImpCasts(StringFind))),
87-
change(cat("absl::StrContains(", node("string_being_searched"),
88-
", ", node("parameter_to_find"), ")")),
89-
cat("use absl::StrContains instead of find() != npos"))});
90-
addInclude(rule, AbseilStringsMatchHeader);
66+
{makeRule(
67+
binaryOperator(hasOperatorName("=="),
68+
hasOperands(ignoringParenImpCasts(StringNpos),
69+
ignoringParenImpCasts(StringFind))),
70+
{changeTo(cat("!absl::StrContains(", node("string_being_searched"),
71+
", ", node("parameter_to_find"), ")")),
72+
addInclude(AbseilStringsMatchHeader)},
73+
cat("use !absl::StrContains instead of find() == npos")),
74+
makeRule(
75+
binaryOperator(hasOperatorName("!="),
76+
hasOperands(ignoringParenImpCasts(StringNpos),
77+
ignoringParenImpCasts(StringFind))),
78+
{changeTo(cat("absl::StrContains(", node("string_being_searched"),
79+
", ", node("parameter_to_find"), ")")),
80+
addInclude(AbseilStringsMatchHeader)},
81+
cat("use absl::StrContains instead "
82+
"of find() != npos"))});
9183
return rule;
9284
}
9385

9486
StringFindStrContainsCheck::StringFindStrContainsCheck(
9587
StringRef Name, ClangTidyContext *Context)
96-
: TransformerClangTidyCheck(&MakeRule, Name, Context),
88+
: TransformerClangTidyCheck(Name, Context),
9789
StringLikeClassesOption(utils::options::parseStringList(
9890
Options.get("StringLikeClasses", DefaultStringLikeClasses))),
9991
AbseilStringsMatchHeaderOption(Options.get(
100-
"AbseilStringsMatchHeader", DefaultAbseilStringsMatchHeader)) {}
92+
"AbseilStringsMatchHeader", DefaultAbseilStringsMatchHeader)) {
93+
setRule(
94+
makeRewriteRule(StringLikeClassesOption, AbseilStringsMatchHeaderOption));
95+
}
10196

10297
bool StringFindStrContainsCheck::isLanguageVersionSupported(
10398
const LangOptions &LangOpts) const {

clang-tools-extra/clangd/AST.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,19 +299,27 @@ SymbolID getSymbolID(const llvm::StringRef MacroName, const MacroInfo *MI,
299299
return SymbolID(USR);
300300
}
301301

302-
// FIXME: This should be handled while printing underlying decls instead.
303302
std::string printType(const QualType QT, const DeclContext &CurContext) {
304303
std::string Result;
305304
llvm::raw_string_ostream OS(Result);
306-
auto Decls =
307-
explicitReferenceTargets(DynTypedNode::create(QT), DeclRelation::Alias);
308-
if (!Decls.empty())
309-
OS << getQualification(CurContext.getParentASTContext(), &CurContext,
310-
Decls.front(),
311-
/*VisibleNamespaces=*/llvm::ArrayRef<std::string>{});
312305
PrintingPolicy PP(CurContext.getParentASTContext().getPrintingPolicy());
313-
PP.SuppressScope = true;
314306
PP.SuppressTagKeyword = true;
307+
PP.SuppressUnwrittenScope = true;
308+
309+
class PrintCB : public PrintingCallbacks {
310+
public:
311+
PrintCB(const DeclContext *CurContext) : CurContext(CurContext) {}
312+
virtual ~PrintCB() {}
313+
virtual bool isScopeVisible(const DeclContext *DC) const override {
314+
return DC->Encloses(CurContext);
315+
}
316+
317+
private:
318+
const DeclContext *CurContext;
319+
};
320+
PrintCB PCB(&CurContext);
321+
PP.Callbacks = &PCB;
322+
315323
QT.print(OS, PP);
316324
return OS.str();
317325
}
@@ -367,7 +375,7 @@ class DeducedTypeVisitor : public RecursiveASTVisitor<DeducedTypeVisitor> {
367375
// Loc of auto in return type (c++14).
368376
auto CurLoc = D->getReturnTypeSourceRange().getBegin();
369377
// Loc of "auto" in operator auto()
370-
if (CurLoc.isInvalid() && dyn_cast<CXXConversionDecl>(D))
378+
if (CurLoc.isInvalid() && isa<CXXConversionDecl>(D))
371379
CurLoc = D->getTypeSourceInfo()->getTypeLoc().getBeginLoc();
372380
// Loc of "auto" in function with trailing return type (c++11).
373381
if (CurLoc.isInvalid())

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,15 +620,17 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
620620
{"documentSymbolProvider", true},
621621
{"workspaceSymbolProvider", true},
622622
{"referencesProvider", true},
623-
{"astProvider", true},
623+
{"astProvider", true}, // clangd extension
624624
{"executeCommandProvider",
625625
llvm::json::Object{
626626
{"commands",
627627
{ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND,
628628
ExecuteCommandParams::CLANGD_APPLY_TWEAK}},
629629
}},
630630
{"typeHierarchyProvider", true},
631-
{"memoryUsageProvider", true}, // clangd extension.
631+
{"memoryUsageProvider", true}, // clangd extension
632+
{"compilationDatabase", // clangd extension
633+
llvm::json::Object{{"automaticReload", true}}},
632634
{"callHierarchyProvider", true},
633635
}}}};
634636
if (Opts.Encoding)

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ void ClangdServer::switchSourceHeader(
549549
// the same directory.
550550
// 2) if 1) fails, we use the AST&Index approach, it is slower but supports
551551
// different code layout.
552-
if (auto CorrespondingFile = getCorrespondingHeaderOrSource(
553-
std::string(Path), TFS.view(llvm::None)))
552+
if (auto CorrespondingFile =
553+
getCorrespondingHeaderOrSource(Path, TFS.view(llvm::None)))
554554
return CB(std::move(CorrespondingFile));
555555
auto Action = [Path = Path.str(), CB = std::move(CB),
556556
this](llvm::Expected<InputsAndAST> InpAST) mutable {

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -828,9 +828,9 @@ struct CompletionRecorder : public CodeCompleteConsumer {
828828
};
829829

830830
struct ScoredSignature {
831-
// When set, requires documentation to be requested from the index with this
832-
// ID.
833-
llvm::Optional<SymbolID> IDForDoc;
831+
// When not null, requires documentation to be requested from the index with
832+
// this ID.
833+
SymbolID IDForDoc;
834834
SignatureInformation Signature;
835835
SignatureQualitySignals Quality;
836836
};
@@ -894,7 +894,7 @@ class SignatureHelpCollector final : public CodeCompleteConsumer {
894894
for (const auto &S : ScoredSignatures) {
895895
if (!S.IDForDoc)
896896
continue;
897-
IndexRequest.IDs.insert(*S.IDForDoc);
897+
IndexRequest.IDs.insert(S.IDForDoc);
898898
}
899899
Index->lookup(IndexRequest, [&](const Symbol &S) {
900900
if (!S.Documentation.empty())
@@ -939,7 +939,7 @@ class SignatureHelpCollector final : public CodeCompleteConsumer {
939939

940940
for (auto &SS : ScoredSignatures) {
941941
auto IndexDocIt =
942-
SS.IDForDoc ? FetchedDocs.find(*SS.IDForDoc) : FetchedDocs.end();
942+
SS.IDForDoc ? FetchedDocs.find(SS.IDForDoc) : FetchedDocs.end();
943943
if (IndexDocIt != FetchedDocs.end())
944944
SS.Signature.documentation = IndexDocIt->second;
945945

@@ -1111,8 +1111,8 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
11111111
offsetToClangLineColumn(Input.ParseInput.Contents, Input.Offset);
11121112

11131113
std::unique_ptr<llvm::MemoryBuffer> ContentsBuffer =
1114-
llvm::MemoryBuffer::getMemBufferCopy(Input.ParseInput.Contents,
1115-
Input.FileName);
1114+
llvm::MemoryBuffer::getMemBuffer(Input.ParseInput.Contents,
1115+
Input.FileName);
11161116
// The diagnostic options must be set before creating a CompilerInstance.
11171117
CI->getDiagnosticOpts().IgnoreWarnings = true;
11181118
// We reuse the preamble whether it's valid or not. This is a

clang-tools-extra/clangd/DumpAST.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,8 @@ class DumpVisitor : public RecursiveASTVisitor<DumpVisitor> {
242242
return "const";
243243
return "";
244244
}
245-
if (isa<IntegerLiteral>(S) || isa<FloatingLiteral>(S) ||
246-
isa<FixedPointLiteral>(S) || isa<CharacterLiteral>(S) ||
247-
isa<ImaginaryLiteral>(S) || isa<CXXBoolLiteralExpr>(S))
245+
if (isa<IntegerLiteral, FloatingLiteral, FixedPointLiteral,
246+
CharacterLiteral, ImaginaryLiteral, CXXBoolLiteralExpr>(S))
248247
return toString([&](raw_ostream &OS) {
249248
S->printPretty(OS, nullptr, Ctx.getPrintingPolicy());
250249
});

clang-tools-extra/clangd/FindTarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ llvm::SmallVector<ReferenceLoc> refInStmt(const Stmt *S) {
843843
void VisitMemberExpr(const MemberExpr *E) {
844844
// Skip destructor calls to avoid duplication: TypeLoc within will be
845845
// visited separately.
846-
if (llvm::dyn_cast<CXXDestructorDecl>(E->getFoundDecl().getDecl()))
846+
if (llvm::isa<CXXDestructorDecl>(E->getFoundDecl().getDecl()))
847847
return;
848848
Refs.push_back(ReferenceLoc{E->getQualifierLoc(),
849849
E->getMemberNameInfo().getLoc(),

clang-tools-extra/clangd/HeaderSourceSwitch.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ namespace clang {
1717
namespace clangd {
1818

1919
llvm::Optional<Path> getCorrespondingHeaderOrSource(
20-
const Path &OriginalFile,
21-
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
20+
PathRef OriginalFile, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
2221
llvm::StringRef SourceExtensions[] = {".cpp", ".c", ".cc", ".cxx",
2322
".c++", ".m", ".mm"};
2423
llvm::StringRef HeaderExtensions[] = {".h", ".hh", ".hpp", ".hxx", ".inc"};
@@ -51,25 +50,23 @@ llvm::Optional<Path> getCorrespondingHeaderOrSource(
5150
NewExts = SourceExtensions;
5251

5352
// Storage for the new path.
54-
llvm::SmallString<128> NewPath = llvm::StringRef(OriginalFile);
53+
llvm::SmallString<128> NewPath = OriginalFile;
5554

5655
// Loop through switched extension candidates.
5756
for (llvm::StringRef NewExt : NewExts) {
5857
llvm::sys::path::replace_extension(NewPath, NewExt);
5958
if (VFS->exists(NewPath))
60-
return NewPath.str().str(); // First str() to convert from SmallString to
61-
// StringRef, second to convert from StringRef
62-
// to std::string
59+
return Path(NewPath);
6360

6461
// Also check NewExt in upper-case, just in case.
6562
llvm::sys::path::replace_extension(NewPath, NewExt.upper());
6663
if (VFS->exists(NewPath))
67-
return NewPath.str().str();
64+
return Path(NewPath);
6865
}
6966
return None;
7067
}
7168

72-
llvm::Optional<Path> getCorrespondingHeaderOrSource(const Path &OriginalFile,
69+
llvm::Optional<Path> getCorrespondingHeaderOrSource(PathRef OriginalFile,
7370
ParsedAST &AST,
7471
const SymbolIndex *Index) {
7572
if (!Index) {
@@ -121,7 +118,7 @@ llvm::Optional<Path> getCorrespondingHeaderOrSource(const Path &OriginalFile,
121118
// candidates.
122119
Best = It;
123120
}
124-
return Path(std::string(Best->first()));
121+
return Path(Best->first());
125122
}
126123

127124
std::vector<const Decl *> getIndexableLocalDecls(ParsedAST &AST) {

clang-tools-extra/clangd/HeaderSourceSwitch.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ namespace clangd {
1818
/// Given a header file, returns the best matching source file, and vice visa.
1919
/// It only uses the filename heuristics to do the inference.
2020
llvm::Optional<Path> getCorrespondingHeaderOrSource(
21-
const Path &OriginalFile,
22-
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS);
21+
PathRef OriginalFile, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS);
2322

2423
/// Given a header file, returns the best matching source file, and vice visa.
2524
/// The heuristics incorporate with the AST and the index (if provided).
26-
llvm::Optional<Path> getCorrespondingHeaderOrSource(const Path &OriginalFile,
25+
llvm::Optional<Path> getCorrespondingHeaderOrSource(PathRef OriginalFile,
2726
ParsedAST &AST,
2827
const SymbolIndex *Index);
2928

clang-tools-extra/clangd/QueryDriverDatabase.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,26 @@ llvm::Optional<DriverInfo> parseDriverOutput(llvm::StringRef Output) {
136136
}
137137

138138
llvm::Optional<DriverInfo>
139-
extractSystemIncludesAndTarget(PathRef Driver, llvm::StringRef Lang,
139+
extractSystemIncludesAndTarget(llvm::SmallString<128> Driver,
140+
llvm::StringRef Lang,
140141
llvm::ArrayRef<std::string> CommandLine,
141142
const llvm::Regex &QueryDriverRegex) {
142143
trace::Span Tracer("Extract system includes and target");
144+
145+
if (!llvm::sys::path::is_absolute(Driver)) {
146+
assert(llvm::none_of(
147+
Driver, [](char C) { return llvm::sys::path::is_separator(C); }));
148+
auto DriverProgram = llvm::sys::findProgramByName(Driver);
149+
if (DriverProgram) {
150+
vlog("System include extraction: driver {0} expanded to {1}", Driver,
151+
*DriverProgram);
152+
Driver = *DriverProgram;
153+
} else {
154+
elog("System include extraction: driver {0} not found in PATH", Driver);
155+
return llvm::None;
156+
}
157+
}
158+
143159
SPAN_ATTACH(Tracer, "driver", Driver);
144160
SPAN_ATTACH(Tracer, "lang", Lang);
145161

@@ -332,7 +348,11 @@ class QueryDriverDatabase : public GlobalCompilationDatabase {
332348
}
333349

334350
llvm::SmallString<128> Driver(Cmd->CommandLine.front());
335-
llvm::sys::fs::make_absolute(Cmd->Directory, Driver);
351+
if (llvm::any_of(Driver,
352+
[](char C) { return llvm::sys::path::is_separator(C); }))
353+
// Driver is a not a single executable name but instead a path (either
354+
// relative or absolute).
355+
llvm::sys::fs::make_absolute(Cmd->Directory, Driver);
336356

337357
if (auto Info =
338358
QueriedDrivers.get(/*Key=*/(Driver + ":" + Lang).str(), [&] {

0 commit comments

Comments
 (0)