Skip to content

Commit 7fac210

Browse files
committed
LLVM and SPIRV-LLVM-Translator pulldown (WW44)
LLVM: llvm/llvm-project@850217686e21 SPIRV-LLVM-Translator: KhronosGroup/SPIRV-LLVM-Translator@89ecd25
2 parents 1eb9717 + 923debe commit 7fac210

File tree

2,271 files changed

+90945
-117281
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,271 files changed

+90945
-117281
lines changed

.github/lockdown.yml

-8
This file was deleted.

.github/workflows/repo-lockdown.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: 'Repo Lockdown'
2+
on:
3+
pull_request_target:
4+
types: opened
5+
6+
permissions:
7+
pull-requests: write
8+
9+
jobs:
10+
action:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: dessant/repo-lockdown@v2
14+
with:
15+
process-only: 'prs'
16+
pr-comment: >
17+
This repository does not accept pull requests.
18+
Please follow http://llvm.org/docs/Contributing.html#how-to-submit-a-patch for contribution to LLVM.

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

+34-48
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "llvm/Support/FormatVariadic.h"
3636
#include "llvm/Support/Regex.h"
3737
#include <tuple>
38+
#include <utility>
3839
#include <vector>
3940
using namespace clang;
4041
using namespace tidy;
@@ -321,11 +322,11 @@ void ClangTidyDiagnosticConsumer::finalizeLastError() {
321322

322323
static bool isNOLINTFound(StringRef NolintDirectiveText, StringRef CheckName,
323324
StringRef Line, size_t *FoundNolintIndex = nullptr,
324-
bool *SuppressionIsSpecific = nullptr) {
325+
StringRef *FoundNolintChecksStr = nullptr) {
325326
if (FoundNolintIndex)
326327
*FoundNolintIndex = StringRef::npos;
327-
if (SuppressionIsSpecific)
328-
*SuppressionIsSpecific = false;
328+
if (FoundNolintChecksStr)
329+
*FoundNolintChecksStr = StringRef();
329330

330331
size_t NolintIndex = Line.find(NolintDirectiveText);
331332
if (NolintIndex == StringRef::npos)
@@ -345,18 +346,13 @@ static bool isNOLINTFound(StringRef NolintDirectiveText, StringRef CheckName,
345346
if (BracketEndIndex != StringRef::npos) {
346347
StringRef ChecksStr =
347348
Line.substr(BracketIndex, BracketEndIndex - BracketIndex);
348-
// Allow disabling all the checks with "*".
349-
if (ChecksStr != "*") {
350-
// Allow specifying a few check names, delimited with comma.
351-
SmallVector<StringRef, 1> Checks;
352-
ChecksStr.split(Checks, ',', -1, false);
353-
llvm::transform(Checks, Checks.begin(),
354-
[](StringRef S) { return S.trim(); });
355-
if (llvm::find(Checks, CheckName) == Checks.end())
356-
return false;
357-
if (SuppressionIsSpecific)
358-
*SuppressionIsSpecific = true;
359-
}
349+
if (FoundNolintChecksStr)
350+
*FoundNolintChecksStr = ChecksStr;
351+
// Allow specifying a few checks with a glob expression, ignoring
352+
// negative globs (which would effectively disable the suppression).
353+
GlobList Globs(ChecksStr, /*KeepNegativeGlobs=*/false);
354+
if (!Globs.contains(CheckName))
355+
return false;
360356
}
361357
}
362358

@@ -388,28 +384,27 @@ static ClangTidyError createNolintError(const ClangTidyContext &Context,
388384
return Error;
389385
}
390386

391-
static Optional<ClangTidyError>
392-
tallyNolintBegins(const ClangTidyContext &Context, const SourceManager &SM,
393-
StringRef CheckName, SmallVector<StringRef> Lines,
394-
SourceLocation LinesLoc,
395-
SmallVector<SourceLocation> &SpecificNolintBegins,
396-
SmallVector<SourceLocation> &GlobalNolintBegins) {
397-
// Keep a running total of how many NOLINT(BEGIN...END) blocks are active.
387+
static Optional<ClangTidyError> tallyNolintBegins(
388+
const ClangTidyContext &Context, const SourceManager &SM,
389+
StringRef CheckName, SmallVector<StringRef> Lines, SourceLocation LinesLoc,
390+
SmallVector<std::pair<SourceLocation, StringRef>> &NolintBegins) {
391+
// Keep a running total of how many NOLINT(BEGIN...END) blocks are active, as
392+
// well as the bracket expression (if any) that was used in the NOLINT
393+
// expression.
398394
size_t NolintIndex;
399-
bool SuppressionIsSpecific;
400-
auto List = [&]() -> SmallVector<SourceLocation> * {
401-
return SuppressionIsSpecific ? &SpecificNolintBegins : &GlobalNolintBegins;
402-
};
395+
StringRef NolintChecksStr;
403396
for (const auto &Line : Lines) {
404397
if (isNOLINTFound("NOLINTBEGIN", CheckName, Line, &NolintIndex,
405-
&SuppressionIsSpecific)) {
398+
&NolintChecksStr)) {
406399
// Check if a new block is being started.
407-
List()->emplace_back(LinesLoc.getLocWithOffset(NolintIndex));
400+
NolintBegins.emplace_back(std::make_pair(
401+
LinesLoc.getLocWithOffset(NolintIndex), NolintChecksStr));
408402
} else if (isNOLINTFound("NOLINTEND", CheckName, Line, &NolintIndex,
409-
&SuppressionIsSpecific)) {
403+
&NolintChecksStr)) {
410404
// Check if the previous block is being closed.
411-
if (!List()->empty()) {
412-
List()->pop_back();
405+
if (!NolintBegins.empty() &&
406+
NolintBegins.back().second == NolintChecksStr) {
407+
NolintBegins.pop_back();
413408
} else {
414409
// Trying to close a nonexistent block. Return a diagnostic about this
415410
// misuse that can be displayed along with the original clang-tidy check
@@ -432,42 +427,33 @@ lineIsWithinNolintBegin(const ClangTidyContext &Context,
432427
StringRef TextAfterDiag) {
433428
Loc = SM.getExpansionRange(Loc).getBegin();
434429
SourceLocation FileStartLoc = SM.getLocForStartOfFile(SM.getFileID(Loc));
430+
SmallVector<std::pair<SourceLocation, StringRef>> NolintBegins;
435431

436432
// Check if there's an open NOLINT(BEGIN...END) block on the previous lines.
437433
SmallVector<StringRef> PrevLines;
438434
TextBeforeDiag.split(PrevLines, '\n');
439-
SmallVector<SourceLocation> SpecificNolintBegins;
440-
SmallVector<SourceLocation> GlobalNolintBegins;
441-
auto Error =
442-
tallyNolintBegins(Context, SM, CheckName, PrevLines, FileStartLoc,
443-
SpecificNolintBegins, GlobalNolintBegins);
435+
auto Error = tallyNolintBegins(Context, SM, CheckName, PrevLines,
436+
FileStartLoc, NolintBegins);
444437
if (Error) {
445438
SuppressionErrors.emplace_back(Error.getValue());
446-
return false;
447439
}
448-
bool WithinNolintBegin =
449-
!SpecificNolintBegins.empty() || !GlobalNolintBegins.empty();
440+
bool WithinNolintBegin = !NolintBegins.empty();
450441

451442
// Check that every block is terminated correctly on the following lines.
452443
SmallVector<StringRef> FollowingLines;
453444
TextAfterDiag.split(FollowingLines, '\n');
454445
Error = tallyNolintBegins(Context, SM, CheckName, FollowingLines, Loc,
455-
SpecificNolintBegins, GlobalNolintBegins);
446+
NolintBegins);
456447
if (Error) {
457448
SuppressionErrors.emplace_back(Error.getValue());
458-
return false;
459449
}
460450

461451
// The following blocks were never closed. Return diagnostics for each
462452
// instance that can be displayed along with the original clang-tidy check
463453
// that the user was attempting to suppress.
464-
for (const auto NolintBegin : SpecificNolintBegins) {
465-
auto Error = createNolintError(Context, SM, NolintBegin, true);
466-
SuppressionErrors.emplace_back(Error);
467-
}
468-
for (const auto NolintBegin : GlobalNolintBegins) {
469-
auto Error = createNolintError(Context, SM, NolintBegin, true);
470-
SuppressionErrors.emplace_back(Error);
454+
for (const auto &NolintBegin : NolintBegins) {
455+
SuppressionErrors.emplace_back(
456+
createNolintError(Context, SM, NolintBegin.first, true));
471457
}
472458

473459
return WithinNolintBegin && SuppressionErrors.empty();

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ static llvm::Regex consumeGlob(StringRef &GlobList) {
4242
return llvm::Regex(RegexText);
4343
}
4444

45-
GlobList::GlobList(StringRef Globs) {
45+
GlobList::GlobList(StringRef Globs, bool KeepNegativeGlobs /* =true */) {
4646
Items.reserve(Globs.count(',') + 1);
4747
do {
4848
GlobListItem Item;
4949
Item.IsPositive = !consumeNegativeIndicator(Globs);
5050
Item.Regex = consumeGlob(Globs);
51-
Items.push_back(std::move(Item));
51+
if (Item.IsPositive || KeepNegativeGlobs)
52+
Items.push_back(std::move(Item));
5253
} while (!Globs.empty());
5354
}
5455

clang-tools-extra/clang-tidy/GlobList.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ class GlobList {
2929
///
3030
/// An empty \p Globs string is interpreted as one glob that matches an empty
3131
/// string.
32-
GlobList(StringRef Globs);
32+
///
33+
/// \p KeepNegativeGlobs a bool flag indicating whether to keep negative
34+
/// globs from \p Globs or not. When false, negative globs are simply ignored.
35+
GlobList(StringRef Globs, bool KeepNegativeGlobs = true);
3336

3437
/// Returns \c true if the pattern matches \p S. The result is the last
3538
/// matching glob's Positive flag.

clang-tools-extra/clangd/ClangdLSPServer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
542542
"^", "&", "#", "?", ".", "=", "\"", "'", "|"}},
543543
{"resolveProvider", false},
544544
// We do extra checks, e.g. that > is part of ->.
545-
{"triggerCharacters", {".", "<", ">", ":", "\"", "/"}},
545+
{"triggerCharacters", {".", "<", ">", ":", "\"", "/", "*"}},
546546
}},
547547
{"semanticTokensProvider",
548548
llvm::json::Object{

clang-tools-extra/clangd/CodeComplete.cpp

+112-1
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,50 @@ class SignatureHelpCollector final : public CodeCompleteConsumer {
10981098
const SymbolIndex *Index;
10991099
}; // SignatureHelpCollector
11001100

1101+
// Used only for completion of C-style comments in function call (i.e.
1102+
// /*foo=*/7). Similar to SignatureHelpCollector, but needs to do less work.
1103+
class ParamNameCollector final : public CodeCompleteConsumer {
1104+
public:
1105+
ParamNameCollector(const clang::CodeCompleteOptions &CodeCompleteOpts,
1106+
std::set<std::string> &ParamNames)
1107+
: CodeCompleteConsumer(CodeCompleteOpts),
1108+
Allocator(std::make_shared<clang::GlobalCodeCompletionAllocator>()),
1109+
CCTUInfo(Allocator), ParamNames(ParamNames) {}
1110+
1111+
void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
1112+
OverloadCandidate *Candidates,
1113+
unsigned NumCandidates,
1114+
SourceLocation OpenParLoc) override {
1115+
assert(CurrentArg <= (unsigned)std::numeric_limits<int>::max() &&
1116+
"too many arguments");
1117+
1118+
for (unsigned I = 0; I < NumCandidates; ++I) {
1119+
OverloadCandidate Candidate = Candidates[I];
1120+
auto *Func = Candidate.getFunction();
1121+
if (!Func || Func->getNumParams() <= CurrentArg)
1122+
continue;
1123+
auto *PVD = Func->getParamDecl(CurrentArg);
1124+
if (!PVD)
1125+
continue;
1126+
auto *Ident = PVD->getIdentifier();
1127+
if (!Ident)
1128+
continue;
1129+
auto Name = Ident->getName();
1130+
if (!Name.empty())
1131+
ParamNames.insert(Name.str());
1132+
}
1133+
}
1134+
1135+
private:
1136+
GlobalCodeCompletionAllocator &getAllocator() override { return *Allocator; }
1137+
1138+
CodeCompletionTUInfo &getCodeCompletionTUInfo() override { return CCTUInfo; }
1139+
1140+
std::shared_ptr<clang::GlobalCodeCompletionAllocator> Allocator;
1141+
CodeCompletionTUInfo CCTUInfo;
1142+
std::set<std::string> &ParamNames;
1143+
};
1144+
11011145
struct SemaCompleteInput {
11021146
PathRef FileName;
11031147
size_t Offset;
@@ -1860,6 +1904,59 @@ CompletionPrefix guessCompletionPrefix(llvm::StringRef Content,
18601904
return Result;
18611905
}
18621906

1907+
// Code complete the argument name on "/*" inside function call.
1908+
// Offset should be pointing to the start of the comment, i.e.:
1909+
// foo(^/*, rather than foo(/*^) where the cursor probably is.
1910+
CodeCompleteResult codeCompleteComment(PathRef FileName, unsigned Offset,
1911+
llvm::StringRef Prefix,
1912+
const PreambleData *Preamble,
1913+
const ParseInputs &ParseInput) {
1914+
if (Preamble == nullptr) // Can't run without Sema.
1915+
return CodeCompleteResult();
1916+
1917+
clang::CodeCompleteOptions Options;
1918+
Options.IncludeGlobals = false;
1919+
Options.IncludeMacros = false;
1920+
Options.IncludeCodePatterns = false;
1921+
Options.IncludeBriefComments = false;
1922+
std::set<std::string> ParamNames;
1923+
// We want to see signatures coming from newly introduced includes, hence a
1924+
// full patch.
1925+
semaCodeComplete(
1926+
std::make_unique<ParamNameCollector>(Options, ParamNames), Options,
1927+
{FileName, Offset, *Preamble,
1928+
PreamblePatch::createFullPatch(FileName, ParseInput, *Preamble),
1929+
ParseInput});
1930+
if (ParamNames.empty())
1931+
return CodeCompleteResult();
1932+
1933+
CodeCompleteResult Result;
1934+
Result.Context = CodeCompletionContext::CCC_NaturalLanguage;
1935+
for (llvm::StringRef Name : ParamNames) {
1936+
if (!Name.startswith(Prefix))
1937+
continue;
1938+
CodeCompletion Item;
1939+
Item.Name = Name.str() + "=";
1940+
Item.Kind = CompletionItemKind::Text;
1941+
Result.Completions.push_back(Item);
1942+
}
1943+
1944+
return Result;
1945+
}
1946+
1947+
// If Offset is inside what looks like argument comment (e.g.
1948+
// "/*^" or "/* foo^"), returns new offset pointing to the start of the /*
1949+
// (place where semaCodeComplete should run).
1950+
llvm::Optional<unsigned>
1951+
maybeFunctionArgumentCommentStart(llvm::StringRef Content) {
1952+
while (!Content.empty() && isAsciiIdentifierContinue(Content.back()))
1953+
Content = Content.drop_back();
1954+
Content = Content.rtrim();
1955+
if (Content.endswith("/*"))
1956+
return Content.size() - 2;
1957+
return None;
1958+
}
1959+
18631960
CodeCompleteResult codeComplete(PathRef FileName, Position Pos,
18641961
const PreambleData *Preamble,
18651962
const ParseInputs &ParseInput,
@@ -1870,6 +1967,19 @@ CodeCompleteResult codeComplete(PathRef FileName, Position Pos,
18701967
elog("Code completion position was invalid {0}", Offset.takeError());
18711968
return CodeCompleteResult();
18721969
}
1970+
1971+
auto Content = llvm::StringRef(ParseInput.Contents).take_front(*Offset);
1972+
if (auto OffsetBeforeComment = maybeFunctionArgumentCommentStart(Content)) {
1973+
// We are doing code completion of a comment, where we currently only
1974+
// support completing param names in function calls. To do this, we
1975+
// require information from Sema, but Sema's comment completion stops at
1976+
// parsing, so we must move back the position before running it, extract
1977+
// information we need and construct completion items ourselves.
1978+
auto CommentPrefix = Content.substr(*OffsetBeforeComment + 2).trim();
1979+
return codeCompleteComment(FileName, *OffsetBeforeComment, CommentPrefix,
1980+
Preamble, ParseInput);
1981+
}
1982+
18731983
auto Flow = CodeCompleteFlow(
18741984
FileName, Preamble ? Preamble->Includes : IncludeStructure(),
18751985
SpecFuzzyFind, Opts);
@@ -2053,7 +2163,8 @@ bool allowImplicitCompletion(llvm::StringRef Content, unsigned Offset) {
20532163
Content = Content.substr(Pos + 1);
20542164

20552165
// Complete after scope operators.
2056-
if (Content.endswith(".") || Content.endswith("->") || Content.endswith("::"))
2166+
if (Content.endswith(".") || Content.endswith("->") ||
2167+
Content.endswith("::") || Content.endswith("/*"))
20572168
return true;
20582169
// Complete after `#include <` and #include `<foo/`.
20592170
if ((Content.endswith("<") || Content.endswith("\"") ||

clang-tools-extra/clangd/HeuristicResolver.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,4 @@ std::vector<const NamedDecl *> HeuristicResolver::resolveDependentMember(
266266
}
267267

268268
} // namespace clangd
269-
} // namespace clang
269+
} // namespace clang

clang-tools-extra/clangd/TUScheduler.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,12 @@ class TUScheduler::HeaderIncluderCache {
286286
void remove(PathRef MainFile) {
287287
std::lock_guard<std::mutex> Lock(Mu);
288288
Association *&First = MainToFirst[MainFile];
289-
if (First)
289+
if (First) {
290290
invalidate(First);
291+
First = nullptr;
292+
}
293+
// MainToFirst entry should stay alive, as Associations might be pointing at
294+
// its key.
291295
}
292296

293297
/// Get the mainfile associated with Header, or the empty string if none.
@@ -901,15 +905,17 @@ void ASTWorker::runWithAST(
901905
void PreambleThread::build(Request Req) {
902906
assert(Req.CI && "Got preamble request with null compiler invocation");
903907
const ParseInputs &Inputs = Req.Inputs;
908+
bool ReusedPreamble = false;
904909

905910
Status.update([&](TUStatus &Status) {
906911
Status.PreambleActivity = PreambleAction::Building;
907912
});
908-
auto _ = llvm::make_scope_exit([this, &Req] {
913+
auto _ = llvm::make_scope_exit([this, &Req, &ReusedPreamble] {
909914
ASTPeer.updatePreamble(std::move(Req.CI), std::move(Req.Inputs),
910915
LatestBuild, std::move(Req.CIDiags),
911916
std::move(Req.WantDiags));
912-
Callbacks.onPreamblePublished(FileName);
917+
if (!ReusedPreamble)
918+
Callbacks.onPreamblePublished(FileName);
913919
});
914920

915921
if (!LatestBuild || Inputs.ForceRebuild) {
@@ -918,6 +924,7 @@ void PreambleThread::build(Request Req) {
918924
} else if (isPreambleCompatible(*LatestBuild, Inputs, FileName, *Req.CI)) {
919925
vlog("Reusing preamble version {0} for version {1} of {2}",
920926
LatestBuild->Version, Inputs.Version, FileName);
927+
ReusedPreamble = true;
921928
return;
922929
} else {
923930
vlog("Rebuilding invalidated preamble for {0} version {1} (previous was "

0 commit comments

Comments
 (0)