Skip to content

Commit 0599a69

Browse files
committed
Merge commit 'b9ba05360e585729458363a53f6cba71d1a8ebb6' into llvmspirv_pulldown
2 parents 8d008b6 + b9ba053 commit 0599a69

File tree

505 files changed

+60177
-7843
lines changed

Some content is hidden

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

505 files changed

+60177
-7843
lines changed

bolt/lib/Core/DebugData.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ void DebugStrOffsetsWriter::initialize(
11661166
"Dwarf String Offsets Byte Size is not supported.");
11671167
uint32_t Index = 0;
11681168
for (uint64_t Offset = 0; Offset < Contr->Size; Offset += DwarfOffsetByteSize)
1169-
IndexToAddressMap[Index++] = *reinterpret_cast<const uint32_t *>(
1169+
IndexToAddressMap[Index++] = support::endian::read32le(
11701170
StrOffsetsSection.Data.data() + Contr->Base + Offset);
11711171
}
11721172

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
265265
return true;
266266
}
267267

268-
DispImm = Inst.getOperand(I).getImm() << 2;
268+
DispImm = Inst.getOperand(I).getImm() * 4;
269269
return true;
270270
}
271271
return false;

clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ const HeaderMapCollector::RegexHeaderMap *getSTLPostfixHeaderMap() {
267267
{"unordered_set$", "<unordered_set>"},
268268
{"utility$", "<utility>"},
269269
{"valarray$", "<valarray>"},
270+
{"variant$", "<variant>"},
270271
{"vector$", "<vector>"},
271272
{"include/complex.h$", "<complex.h>"},
272273
{"include/ctype.h$", "<cctype>"},

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
494494
BackgroundIndexProgressState = BackgroundIndexProgress::Empty;
495495
BackgroundIndexSkipCreate = Params.capabilities.ImplicitProgressCreation;
496496
Opts.ImplicitCancellation = !Params.capabilities.CancelsStaleRequests;
497+
Opts.PublishInactiveRegions = Params.capabilities.InactiveRegions;
497498

498499
if (Opts.UseDirBasedCDB) {
499500
DirectoryBasedGlobalCompilationDatabase::Options CDBOpts(TFS);
@@ -582,6 +583,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
582583
{"memoryUsageProvider", true}, // clangd extension
583584
{"compilationDatabase", // clangd extension
584585
llvm::json::Object{{"automaticReload", true}}},
586+
{"inactiveRegionsProvider", true}, // clangd extension
585587
{"callHierarchyProvider", true},
586588
{"clangdInlayHintsProvider", true},
587589
{"inlayHintProvider", true},
@@ -1625,6 +1627,8 @@ void ClangdLSPServer::bindMethods(LSPBinder &Bind,
16251627

16261628
ApplyWorkspaceEdit = Bind.outgoingMethod("workspace/applyEdit");
16271629
PublishDiagnostics = Bind.outgoingNotification("textDocument/publishDiagnostics");
1630+
if (Caps.InactiveRegions)
1631+
PublishInactiveRegions = Bind.outgoingNotification("textDocument/inactiveRegions");
16281632
ShowMessage = Bind.outgoingNotification("window/showMessage");
16291633
NotifyFileStatus = Bind.outgoingNotification("textDocument/clangd.fileStatus");
16301634
CreateWorkDoneProgress = Bind.outgoingMethod("window/workDoneProgress/create");
@@ -1722,6 +1726,15 @@ void ClangdLSPServer::onDiagnosticsReady(PathRef File, llvm::StringRef Version,
17221726
PublishDiagnostics(Notification);
17231727
}
17241728

1729+
void ClangdLSPServer::onInactiveRegionsReady(
1730+
PathRef File, std::vector<Range> InactiveRegions) {
1731+
InactiveRegionsParams Notification;
1732+
Notification.TextDocument = {URIForFile::canonicalize(File, /*TUPath=*/File)};
1733+
Notification.InactiveRegions = std::move(InactiveRegions);
1734+
1735+
PublishInactiveRegions(Notification);
1736+
}
1737+
17251738
void ClangdLSPServer::onBackgroundIndexProgress(
17261739
const BackgroundQueue::Stats &Stats) {
17271740
static const char ProgressToken[] = "backgroundIndexProgress";

clang-tools-extra/clangd/ClangdLSPServer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
8383
void onFileUpdated(PathRef File, const TUStatus &Status) override;
8484
void onBackgroundIndexProgress(const BackgroundQueue::Stats &Stats) override;
8585
void onSemanticsMaybeChanged(PathRef File) override;
86+
void onInactiveRegionsReady(PathRef File,
87+
std::vector<Range> InactiveRegions) override;
8688

8789
// LSP methods. Notifications have signature void(const Params&).
8890
// Calls have signature void(const Params&, Callback<Response>).
@@ -180,6 +182,7 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
180182
LSPBinder::OutgoingNotification<ShowMessageParams> ShowMessage;
181183
LSPBinder::OutgoingNotification<PublishDiagnosticsParams> PublishDiagnostics;
182184
LSPBinder::OutgoingNotification<FileStatus> NotifyFileStatus;
185+
LSPBinder::OutgoingNotification<InactiveRegionsParams> PublishInactiveRegions;
183186
LSPBinder::OutgoingMethod<WorkDoneProgressCreateParams, std::nullptr_t>
184187
CreateWorkDoneProgress;
185188
LSPBinder::OutgoingNotification<ProgressParams<WorkDoneProgressBegin>>

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ namespace {
6161
struct UpdateIndexCallbacks : public ParsingCallbacks {
6262
UpdateIndexCallbacks(FileIndex *FIndex,
6363
ClangdServer::Callbacks *ServerCallbacks,
64-
const ThreadsafeFS &TFS, AsyncTaskRunner *Tasks)
64+
const ThreadsafeFS &TFS, AsyncTaskRunner *Tasks,
65+
bool CollectInactiveRegions)
6566
: FIndex(FIndex), ServerCallbacks(ServerCallbacks), TFS(TFS),
66-
Stdlib{std::make_shared<StdLibSet>()}, Tasks(Tasks) {}
67+
Stdlib{std::make_shared<StdLibSet>()}, Tasks(Tasks),
68+
CollectInactiveRegions(CollectInactiveRegions) {}
6769

6870
void onPreambleAST(PathRef Path, llvm::StringRef Version,
6971
const CompilerInvocation &CI, ASTContext &Ctx,
@@ -113,6 +115,10 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
113115
Publish([&]() {
114116
ServerCallbacks->onDiagnosticsReady(Path, AST.version(),
115117
std::move(Diagnostics));
118+
if (CollectInactiveRegions) {
119+
ServerCallbacks->onInactiveRegionsReady(
120+
Path, std::move(AST.getMacros().SkippedRanges));
121+
}
116122
});
117123
}
118124

@@ -139,6 +145,7 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
139145
const ThreadsafeFS &TFS;
140146
std::shared_ptr<StdLibSet> Stdlib;
141147
AsyncTaskRunner *Tasks;
148+
bool CollectInactiveRegions;
142149
};
143150

144151
class DraftStoreFS : public ThreadsafeFS {
@@ -189,6 +196,7 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
189196
LineFoldingOnly(Opts.LineFoldingOnly),
190197
PreambleParseForwardingFunctions(Opts.PreambleParseForwardingFunctions),
191198
ImportInsertions(Opts.ImportInsertions),
199+
PublishInactiveRegions(Opts.PublishInactiveRegions),
192200
WorkspaceRoot(Opts.WorkspaceRoot),
193201
Transient(Opts.ImplicitCancellation ? TUScheduler::InvalidateOnUpdate
194202
: TUScheduler::NoInvalidation),
@@ -201,7 +209,8 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
201209
WorkScheduler.emplace(CDB, TUScheduler::Options(Opts),
202210
std::make_unique<UpdateIndexCallbacks>(
203211
DynamicIdx.get(), Callbacks, TFS,
204-
IndexTasks ? &*IndexTasks : nullptr));
212+
IndexTasks ? &*IndexTasks : nullptr,
213+
PublishInactiveRegions));
205214
// Adds an index to the stack, at higher priority than existing indexes.
206215
auto AddIndex = [&](SymbolIndex *Idx) {
207216
if (this->Index != nullptr) {
@@ -956,12 +965,17 @@ void ClangdServer::documentLinks(PathRef File,
956965

957966
void ClangdServer::semanticHighlights(
958967
PathRef File, Callback<std::vector<HighlightingToken>> CB) {
959-
auto Action =
960-
[CB = std::move(CB)](llvm::Expected<InputsAndAST> InpAST) mutable {
961-
if (!InpAST)
962-
return CB(InpAST.takeError());
963-
CB(clangd::getSemanticHighlightings(InpAST->AST));
964-
};
968+
969+
auto Action = [CB = std::move(CB),
970+
PublishInactiveRegions = PublishInactiveRegions](
971+
llvm::Expected<InputsAndAST> InpAST) mutable {
972+
if (!InpAST)
973+
return CB(InpAST.takeError());
974+
// Include inactive regions in semantic highlighting tokens only if the
975+
// client doesn't support a dedicated protocol for being informed about
976+
// them.
977+
CB(clangd::getSemanticHighlightings(InpAST->AST, !PublishInactiveRegions));
978+
};
965979
WorkScheduler->runWithAST("SemanticHighlights", File, std::move(Action),
966980
Transient);
967981
}

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ class ClangdServer {
8484
/// build finishes, we can provide more accurate semantic tokens, so we
8585
/// should tell the client to refresh.
8686
virtual void onSemanticsMaybeChanged(PathRef File) {}
87+
88+
/// Called by ClangdServer when some \p InactiveRegions for \p File are
89+
/// ready.
90+
virtual void onInactiveRegionsReady(PathRef File,
91+
std::vector<Range> InactiveRegions) {}
8792
};
8893
/// Creates a context provider that loads and installs config.
8994
/// Errors in loading config are reported as diagnostics via Callbacks.
@@ -175,6 +180,10 @@ class ClangdServer {
175180
/// instead of #include.
176181
bool ImportInsertions = false;
177182

183+
/// Whether to collect and publish information about inactive preprocessor
184+
/// regions in the document.
185+
bool PublishInactiveRegions = false;
186+
178187
explicit operator TUScheduler::Options() const;
179188
};
180189
// Sensible default options for use in tests.
@@ -440,6 +449,8 @@ class ClangdServer {
440449

441450
bool ImportInsertions = false;
442451

452+
bool PublishInactiveRegions = false;
453+
443454
// GUARDED_BY(CachedCompletionFuzzyFindRequestMutex)
444455
llvm::StringMap<std::optional<FuzzyFindRequest>>
445456
CachedCompletionFuzzyFindRequestByFile;

clang-tools-extra/clangd/Diagnostics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,9 +715,9 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
715715
D.InsideMainFile = isInsideMainFile(PatchLoc, SM);
716716
D.Range = diagnosticRange(Info, *LangOpts);
717717
auto FID = SM.getFileID(Info.getLocation());
718-
if (auto *FE = SM.getFileEntryForID(FID)) {
718+
if (const auto FE = SM.getFileEntryRefForID(FID)) {
719719
D.File = FE->getName().str();
720-
D.AbsFile = getCanonicalPath(FE, SM);
720+
D.AbsFile = getCanonicalPath(*FE, SM);
721721
}
722722
D.ID = Info.getID();
723723
return D;

clang-tools-extra/clangd/IncludeCleaner.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ convertIncludes(const SourceManager &SM,
317317
std::string spellHeader(ParsedAST &AST, const FileEntry *MainFile,
318318
include_cleaner::Header Provider) {
319319
if (Provider.kind() == include_cleaner::Header::Physical) {
320-
if (auto CanonicalPath =
321-
getCanonicalPath(Provider.physical(), AST.getSourceManager())) {
320+
if (auto CanonicalPath = getCanonicalPath(Provider.physical()->getLastRef(),
321+
AST.getSourceManager())) {
322322
std::string SpelledHeader =
323323
llvm::cantFail(URI::includeSpelling(URI::create(*CanonicalPath)));
324324
if (!SpelledHeader.empty())
@@ -405,9 +405,14 @@ IncludeCleanerFindings computeIncludeCleanerFindings(ParsedAST &AST) {
405405
// through an #include.
406406
while (SM.getFileID(Loc) != SM.getMainFileID())
407407
Loc = SM.getIncludeLoc(SM.getFileID(Loc));
408-
const auto *Token = AST.getTokens().spelledTokenAt(Loc);
409-
MissingIncludeDiagInfo DiagInfo{Ref.Target, Token->range(SM),
410-
Providers};
408+
auto TouchingTokens =
409+
syntax::spelledTokensTouching(Loc, AST.getTokens());
410+
assert(!TouchingTokens.empty());
411+
// Loc points to the start offset of the ref token, here we use the last
412+
// element of the TouchingTokens, e.g. avoid getting the "::" for
413+
// "ns::^abc".
414+
MissingIncludeDiagInfo DiagInfo{
415+
Ref.Target, TouchingTokens.back().range(SM), Providers};
411416
MissingIncludes.push_back(std::move(DiagInfo));
412417
});
413418
std::vector<const Inclusion *> UnusedIncludes =

clang-tools-extra/clangd/Protocol.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,13 @@ bool fromJSON(const llvm::json::Value &Params, ClientCapabilities &R,
338338
SemanticHighlighting->getBoolean("semanticHighlighting"))
339339
R.TheiaSemanticHighlighting = *SemanticHighlightingSupport;
340340
}
341+
if (auto *InactiveRegions =
342+
TextDocument->getObject("inactiveRegionsCapabilities")) {
343+
if (auto InactiveRegionsSupport =
344+
InactiveRegions->getBoolean("inactiveRegions")) {
345+
R.InactiveRegions = *InactiveRegionsSupport;
346+
}
347+
}
341348
if (TextDocument->getObject("semanticTokens"))
342349
R.SemanticTokens = true;
343350
if (auto *Diagnostics = TextDocument->getObject("publishDiagnostics")) {
@@ -1174,6 +1181,12 @@ bool fromJSON(const llvm::json::Value &Params, SemanticTokensDeltaParams &R,
11741181
O.map("previousResultId", R.previousResultId);
11751182
}
11761183

1184+
llvm::json::Value toJSON(const InactiveRegionsParams &InactiveRegions) {
1185+
return llvm::json::Object{
1186+
{"textDocument", InactiveRegions.TextDocument},
1187+
{"regions", std::move(InactiveRegions.InactiveRegions)}};
1188+
}
1189+
11771190
llvm::raw_ostream &operator<<(llvm::raw_ostream &O,
11781191
const DocumentHighlight &V) {
11791192
O << V.range;

clang-tools-extra/clangd/Protocol.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,10 @@ struct ClientCapabilities {
516516
/// Whether the client implementation supports a refresh request sent from the
517517
/// server to the client.
518518
bool SemanticTokenRefreshSupport = false;
519+
520+
/// Whether the client supports the textDocument/inactiveRegions
521+
/// notification. This is a clangd extension.
522+
bool InactiveRegions = false;
519523
};
520524
bool fromJSON(const llvm::json::Value &, ClientCapabilities &,
521525
llvm::json::Path);
@@ -1736,6 +1740,16 @@ struct SemanticTokensOrDelta {
17361740
};
17371741
llvm::json::Value toJSON(const SemanticTokensOrDelta &);
17381742

1743+
/// Parameters for the inactive regions (server-side) push notification.
1744+
/// This is a clangd extension.
1745+
struct InactiveRegionsParams {
1746+
/// The textdocument these inactive regions belong to.
1747+
TextDocumentIdentifier TextDocument;
1748+
/// The inactive regions that should be sent.
1749+
std::vector<Range> InactiveRegions;
1750+
};
1751+
llvm::json::Value toJSON(const InactiveRegionsParams &InactiveRegions);
1752+
17391753
struct SelectionRangeParams {
17401754
/// The text document.
17411755
TextDocumentIdentifier textDocument;

clang-tools-extra/clangd/SemanticHighlighting.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,10 @@ resolveConflict(ArrayRef<HighlightingToken> Tokens) {
357357
/// Consumes source locations and maps them to text ranges for highlightings.
358358
class HighlightingsBuilder {
359359
public:
360-
HighlightingsBuilder(const ParsedAST &AST)
360+
HighlightingsBuilder(const ParsedAST &AST, bool IncludeInactiveRegionTokens)
361361
: TB(AST.getTokens()), SourceMgr(AST.getSourceManager()),
362-
LangOpts(AST.getLangOpts()) {}
362+
LangOpts(AST.getLangOpts()),
363+
IncludeInactiveRegionTokens(IncludeInactiveRegionTokens) {}
363364

364365
HighlightingToken &addToken(SourceLocation Loc, HighlightingKind Kind) {
365366
auto Range = getRangeForSourceLocation(Loc);
@@ -458,6 +459,9 @@ class HighlightingsBuilder {
458459
TokRef = TokRef.drop_front(Conflicting.size());
459460
}
460461

462+
if (!IncludeInactiveRegionTokens)
463+
return NonConflicting;
464+
461465
const auto &SM = AST.getSourceManager();
462466
StringRef MainCode = SM.getBufferOrFake(SM.getMainFileID()).getBuffer();
463467

@@ -531,6 +535,7 @@ class HighlightingsBuilder {
531535
const syntax::TokenBuffer &TB;
532536
const SourceManager &SourceMgr;
533537
const LangOptions &LangOpts;
538+
bool IncludeInactiveRegionTokens;
534539
std::vector<HighlightingToken> Tokens;
535540
std::map<Range, llvm::SmallVector<HighlightingModifier, 1>> ExtraModifiers;
536541
const HeuristicResolver *Resolver = nullptr;
@@ -1096,10 +1101,11 @@ class CollectExtraHighlightings
10961101
};
10971102
} // namespace
10981103

1099-
std::vector<HighlightingToken> getSemanticHighlightings(ParsedAST &AST) {
1104+
std::vector<HighlightingToken>
1105+
getSemanticHighlightings(ParsedAST &AST, bool IncludeInactiveRegionTokens) {
11001106
auto &C = AST.getASTContext();
11011107
// Add highlightings for AST nodes.
1102-
HighlightingsBuilder Builder(AST);
1108+
HighlightingsBuilder Builder(AST, IncludeInactiveRegionTokens);
11031109
// Highlight 'decltype' and 'auto' as their underlying types.
11041110
CollectExtraHighlightings(Builder).TraverseAST(C);
11051111
// Highlight all decls and references coming from the AST.

clang-tools-extra/clangd/SemanticHighlighting.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ bool operator<(const HighlightingToken &L, const HighlightingToken &R);
106106

107107
// Returns all HighlightingTokens from an AST. Only generates highlights for the
108108
// main AST.
109-
std::vector<HighlightingToken> getSemanticHighlightings(ParsedAST &AST);
109+
std::vector<HighlightingToken>
110+
getSemanticHighlightings(ParsedAST &AST, bool IncludeInactiveRegionTokens);
110111

111112
std::vector<SemanticToken> toSemanticTokens(llvm::ArrayRef<HighlightingToken>,
112113
llvm::StringRef Code);

clang-tools-extra/clangd/SourceCode.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "Protocol.h"
1313
#include "support/Context.h"
1414
#include "support/Logger.h"
15+
#include "clang/Basic/FileEntry.h"
1516
#include "clang/Basic/LangOptions.h"
1617
#include "clang/Basic/SourceLocation.h"
1718
#include "clang/Basic/SourceManager.h"
@@ -512,12 +513,9 @@ std::vector<TextEdit> replacementsToEdits(llvm::StringRef Code,
512513
return Edits;
513514
}
514515

515-
std::optional<std::string> getCanonicalPath(const FileEntry *F,
516+
std::optional<std::string> getCanonicalPath(const FileEntryRef F,
516517
const SourceManager &SourceMgr) {
517-
if (!F)
518-
return std::nullopt;
519-
520-
llvm::SmallString<128> FilePath = F->getName();
518+
llvm::SmallString<128> FilePath = F.getName();
521519
if (!llvm::sys::path::is_absolute(FilePath)) {
522520
if (auto EC =
523521
SourceMgr.getFileManager().getVirtualFileSystem().makeAbsolute(

clang-tools-extra/clangd/SourceCode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ TextEdit toTextEdit(const FixItHint &FixIt, const SourceManager &M,
163163
/// This function should be used when paths needs to be used outside the
164164
/// component that generate it, so that paths are normalized as much as
165165
/// possible.
166-
std::optional<std::string> getCanonicalPath(const FileEntry *F,
166+
std::optional<std::string> getCanonicalPath(const FileEntryRef F,
167167
const SourceManager &SourceMgr);
168168

169169
/// Choose the clang-format style we should apply to a certain file.

0 commit comments

Comments
 (0)