Skip to content

Commit e946a0f

Browse files
authored
LLVM and SPIRV-LLVM-Translator pulldown (WW27) #4006
LLVM: llvm/llvm-project@7c73c2e SPIRV-LLVM-Translator: KhronosGroup/SPIRV-LLVM-Translator@a84f589
2 parents 8f38045 + b5c4b14 commit e946a0f

File tree

2,090 files changed

+126876
-111964
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,090 files changed

+126876
-111964
lines changed

.mailmap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#
2323
# Please keep this file sorted.
2424

25+
26+
2527
2628
2729
@@ -30,3 +32,4 @@ Jon Roelofs <[email protected]> Jon Roelofs <[email protected]>
3032
Jon Roelofs <[email protected]> Jonathan Roelofs <[email protected]>
3133
Jon Roelofs <[email protected]> Jonathan Roelofs <[email protected]>
3234
Martin Storsjö <[email protected]>
35+
Saleem Abdulrasool <[email protected]> <[email protected]>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ llvm::Optional<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
150150
unsigned EditDistance = 3;
151151
for (const auto &NameAndEnum : Mapping) {
152152
if (IgnoreCase) {
153-
if (Value.equals_lower(NameAndEnum.second))
153+
if (Value.equals_insensitive(NameAndEnum.second))
154154
return NameAndEnum.first;
155155
} else if (Value.equals(NameAndEnum.second)) {
156156
return NameAndEnum.first;
157-
} else if (Value.equals_lower(NameAndEnum.second)) {
157+
} else if (Value.equals_insensitive(NameAndEnum.second)) {
158158
Closest = NameAndEnum.second;
159159
EditDistance = 0;
160160
continue;

clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ void KernelNameRestrictionPPCallbacks::InclusionDirective(
7070

7171
bool KernelNameRestrictionPPCallbacks::fileNameIsRestricted(
7272
StringRef FileName) {
73-
return FileName.equals_lower("kernel.cl") ||
74-
FileName.equals_lower("verilog.cl") ||
75-
FileName.equals_lower("vhdl.cl");
73+
return FileName.equals_insensitive("kernel.cl") ||
74+
FileName.equals_insensitive("verilog.cl") ||
75+
FileName.equals_insensitive("vhdl.cl");
7676
}
7777

7878
void KernelNameRestrictionPPCallbacks::EndOfMainFile() {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ static bool sameName(StringRef InComment, StringRef InDecl, bool StrictMode) {
176176
return InComment == InDecl;
177177
InComment = InComment.trim('_');
178178
InDecl = InDecl.trim('_');
179-
// FIXME: compare_lower only works for ASCII.
180-
return InComment.compare_lower(InDecl) == 0;
179+
// FIXME: compare_insensitive only works for ASCII.
180+
return InComment.compare_insensitive(InDecl) == 0;
181181
}
182182

183183
static bool looksLikeExpectMethod(const CXXMethodDecl *Expect) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void PreferMemberInitializerCheck::check(
159159
if (S->getBeginLoc().isMacroID()) {
160160
StringRef MacroName = Lexer::getImmediateMacroName(
161161
S->getBeginLoc(), *Result.SourceManager, getLangOpts());
162-
if (MacroName.contains_lower("assert"))
162+
if (MacroName.contains_insensitive("assert"))
163163
return;
164164
}
165165
if (isControlStatement(S))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ void StaticAssertCheck::check(const MatchFinder::MatchResult &Result) {
104104

105105
StringRef FalseMacroName =
106106
Lexer::getImmediateMacroName(FalseLiteralLoc, SM, Opts);
107-
if (FalseMacroName.compare_lower("false") == 0 ||
108-
FalseMacroName.compare_lower("null") == 0)
107+
if (FalseMacroName.compare_insensitive("false") == 0 ||
108+
FalseMacroName.compare_insensitive("null") == 0)
109109
return;
110110
}
111111

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ bool nameMatch(StringRef L, StringRef R, bool Strict) {
9393
return L.empty() || R.empty() || L == R;
9494
// We allow two names if one is a prefix/suffix of the other, ignoring case.
9595
// Important special case: this is true if either parameter has no name!
96-
return L.startswith_lower(R) || R.startswith_lower(L) ||
97-
L.endswith_lower(R) || R.endswith_lower(L);
96+
return L.startswith_insensitive(R) || R.startswith_insensitive(L) ||
97+
L.endswith_insensitive(R) || R.endswith_insensitive(L);
9898
}
9999

100100
DifferingParamsContainer

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ getNewSuffix(llvm::StringRef OldSuffix,
9393
// Else, find matching suffix, case-*insensitive*ly.
9494
auto NewSuffix = llvm::find_if(
9595
NewSuffixes, [OldSuffix](const std::string &PotentialNewSuffix) {
96-
return OldSuffix.equals_lower(PotentialNewSuffix);
96+
return OldSuffix.equals_insensitive(PotentialNewSuffix);
9797
});
9898
// Have a match, return it.
9999
if (NewSuffix != NewSuffixes.end())

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include "llvm/ADT/SmallVector.h"
6363
#include "llvm/ADT/StringExtras.h"
6464
#include "llvm/ADT/StringRef.h"
65+
#include "llvm/Support/Casting.h"
6566
#include "llvm/Support/Compiler.h"
6667
#include "llvm/Support/Debug.h"
6768
#include "llvm/Support/Error.h"
@@ -1679,7 +1680,7 @@ class CodeCompleteFlow {
16791680
C.SemaResult->Kind == CodeCompletionResult::RK_Macro) ||
16801681
(C.IndexResult &&
16811682
C.IndexResult->SymInfo.Kind == index::SymbolKind::Macro)) &&
1682-
!C.Name.startswith_lower(Filter->pattern()))
1683+
!C.Name.startswith_insensitive(Filter->pattern()))
16831684
return None;
16841685
return Filter->match(C.Name);
16851686
}
@@ -1910,6 +1911,13 @@ bool isIndexedForCodeCompletion(const NamedDecl &ND, ASTContext &ASTCtx) {
19101911
if (isExplicitTemplateSpecialization(&ND))
19111912
return false;
19121913

1914+
// Category decls are not useful on their own outside the interface or
1915+
// implementation blocks. Moreover, sema already provides completion for
1916+
// these, even if it requires preamble deserialization. So by excluding them
1917+
// from the index, we reduce the noise in all the other completion scopes.
1918+
if (llvm::isa<ObjCCategoryDecl>(&ND) || llvm::isa<ObjCCategoryImplDecl>(&ND))
1919+
return false;
1920+
19131921
if (InTopLevelScope(ND))
19141922
return true;
19151923

clang-tools-extra/clangd/CompileCommands.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ enum DriverMode : unsigned char {
296296
DriverMode getDriverMode(const std::vector<std::string> &Args) {
297297
DriverMode Mode = DM_GCC;
298298
llvm::StringRef Argv0 = Args.front();
299-
if (Argv0.endswith_lower(".exe"))
299+
if (Argv0.endswith_insensitive(".exe"))
300300
Argv0 = Argv0.drop_back(strlen(".exe"));
301-
if (Argv0.endswith_lower("cl"))
301+
if (Argv0.endswith_insensitive("cl"))
302302
Mode = DM_CL;
303303
for (const llvm::StringRef Arg : Args) {
304304
if (Arg == "--driver-mode=cl") {

clang-tools-extra/clangd/ConfigYAML.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class Parser {
169169

170170
void parse(Fragment::IndexBlock::ExternalBlock &F,
171171
Located<std::string> ExternalVal) {
172-
if (!llvm::StringRef(*ExternalVal).equals_lower("none")) {
172+
if (!llvm::StringRef(*ExternalVal).equals_insensitive("none")) {
173173
error("Only scalar value supported for External is 'None'",
174174
ExternalVal.Range);
175175
return;

clang-tools-extra/clangd/HeaderSourceSwitch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ llvm::Optional<Path> getCorrespondingHeaderOrSource(
2727
// Lookup in a list of known extensions.
2828
auto SourceIter =
2929
llvm::find_if(SourceExtensions, [&PathExt](PathRef SourceExt) {
30-
return SourceExt.equals_lower(PathExt);
30+
return SourceExt.equals_insensitive(PathExt);
3131
});
3232
bool IsSource = SourceIter != std::end(SourceExtensions);
3333

3434
auto HeaderIter =
3535
llvm::find_if(HeaderExtensions, [&PathExt](PathRef HeaderExt) {
36-
return HeaderExt.equals_lower(PathExt);
36+
return HeaderExt.equals_insensitive(PathExt);
3737
});
3838
bool IsHeader = HeaderIter != std::end(HeaderExtensions);
3939

clang-tools-extra/clangd/InlayHints.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
156156
return false;
157157

158158
StringRef Name = getSimpleName(*Callee);
159-
if (!Name.startswith_lower("set"))
159+
if (!Name.startswith_insensitive("set"))
160160
return false;
161161

162162
// In addition to checking that the function has one parameter and its
@@ -168,10 +168,10 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
168168
// This currently doesn't handle cases where params use snake_case
169169
// and functions don't, e.g.
170170
// void setExceptionHandler(EHFunc exception_handler);
171-
// We could improve this by replacing `equals_lower` with some
171+
// We could improve this by replacing `equals_insensitive` with some
172172
// `sloppy_equals` which ignores case and also skips underscores.
173173
StringRef WhatItIsSetting = Name.substr(3).ltrim("_");
174-
return WhatItIsSetting.equals_lower(ParamNames[0]);
174+
return WhatItIsSetting.equals_insensitive(ParamNames[0]);
175175
}
176176

177177
bool shouldHint(const Expr *Arg, StringRef ParamName) {

clang-tools-extra/clangd/Quality.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ static llvm::Optional<llvm::StringRef>
378378
wordMatching(llvm::StringRef Name, const llvm::StringSet<> *ContextWords) {
379379
if (ContextWords)
380380
for (const auto &Word : ContextWords->keys())
381-
if (Name.contains_lower(Word))
381+
if (Name.contains_insensitive(Word))
382382
return Word;
383383
return llvm::None;
384384
}
@@ -552,7 +552,7 @@ evaluateDecisionForest(const SymbolQualitySignals &Quality,
552552
int NumMatch = 0;
553553
if (Relevance.ContextWords) {
554554
for (const auto &Word : Relevance.ContextWords->keys()) {
555-
if (Relevance.Name.contains_lower(Word)) {
555+
if (Relevance.Name.contains_insensitive(Word)) {
556556
++NumMatch;
557557
}
558558
}

clang-tools-extra/clangd/index/SymbolCollector.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ class SymbolCollector::HeaderFileURICache {
285285
Line = Line.ltrim();
286286
if (!Line.startswith("error"))
287287
return false;
288-
return Line.contains_lower("includ"); // Matches "include" or "including".
288+
return Line.contains_insensitive(
289+
"includ"); // Matches "include" or "including".
289290
}
290291

291292
// Heuristically headers that only want to be included via an umbrella.

clang-tools-extra/clangd/index/remote/server/Server.cpp

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,18 @@
3737
#include <grpc++/grpc++.h>
3838
#include <grpc++/health_check_service_interface.h>
3939
#include <memory>
40+
#include <string>
4041
#include <thread>
42+
#include <utility>
4143

4244
#if ENABLE_GRPC_REFLECTION
4345
#include <grpc++/ext/proto_server_reflection_plugin.h>
4446
#endif
4547

48+
#ifdef __GLIBC__
49+
#include <malloc.h>
50+
#endif
51+
4652
namespace clang {
4753
namespace clangd {
4854
namespace remote {
@@ -74,6 +80,12 @@ llvm::cl::opt<bool> LogPublic{
7480
llvm::cl::init(false),
7581
};
7682

83+
llvm::cl::opt<std::string> LogPrefix{
84+
"log-prefix",
85+
llvm::cl::desc("A string that'll be prepended to all log statements. "
86+
"Useful when running multiple instances on same host."),
87+
};
88+
7789
llvm::cl::opt<std::string> TraceFile(
7890
"trace-file",
7991
llvm::cl::desc("Path to the file where tracer logs will be stored"));
@@ -354,12 +366,25 @@ class Monitor final : public v1::Monitor::Service {
354366
std::atomic<llvm::sys::TimePoint<>> IndexBuildTime;
355367
};
356368

369+
void maybeTrimMemory() {
370+
#if defined(__GLIBC__) && CLANGD_MALLOC_TRIM
371+
malloc_trim(0);
372+
#endif
373+
}
374+
357375
// Detect changes in \p IndexPath file and load new versions of the index
358376
// whenever they become available.
359377
void hotReload(clangd::SwapIndex &Index, llvm::StringRef IndexPath,
360378
llvm::vfs::Status &LastStatus,
361379
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &FS,
362380
Monitor &Monitor) {
381+
// glibc malloc doesn't shrink an arena if there are items living at the end,
382+
// which might happen since we destroy the old index after building new one.
383+
// Trim more aggresively to keep memory usage of the server low.
384+
// Note that we do it deliberately here rather than after Index.reset(),
385+
// because old index might still be kept alive after the reset call if we are
386+
// serving requests.
387+
maybeTrimMemory();
363388
auto Status = FS->status(IndexPath);
364389
// Requested file is same as loaded index: no reload is needed.
365390
if (!Status || (Status->getLastModificationTime() ==
@@ -410,27 +435,48 @@ void runServerAndWait(clangd::SymbolIndex &Index, llvm::StringRef ServerAddress,
410435
ServerShutdownWatcher.join();
411436
}
412437

413-
std::unique_ptr<Logger> makeLogger(llvm::raw_ostream &OS) {
414-
if (!LogPublic)
415-
return std::make_unique<StreamLogger>(OS, LogLevel);
416-
// Redacted mode:
417-
// - messages outside the scope of a request: log fully
418-
// - messages tagged [public]: log fully
419-
// - errors: log the format string
420-
// - others: drop
421-
class RedactedLogger : public StreamLogger {
438+
std::unique_ptr<Logger> makeLogger(llvm::StringRef LogPrefix,
439+
llvm::raw_ostream &OS) {
440+
std::unique_ptr<Logger> Base;
441+
if (LogPublic) {
442+
// Redacted mode:
443+
// - messages outside the scope of a request: log fully
444+
// - messages tagged [public]: log fully
445+
// - errors: log the format string
446+
// - others: drop
447+
class RedactedLogger : public StreamLogger {
448+
public:
449+
using StreamLogger::StreamLogger;
450+
void log(Level L, const char *Fmt,
451+
const llvm::formatv_object_base &Message) override {
452+
if (Context::current().get(CurrentRequest) == nullptr ||
453+
llvm::StringRef(Fmt).startswith("[public]"))
454+
return StreamLogger::log(L, Fmt, Message);
455+
if (L >= Error)
456+
return StreamLogger::log(L, Fmt,
457+
llvm::formatv("[redacted] {0}", Fmt));
458+
}
459+
};
460+
Base = std::make_unique<RedactedLogger>(OS, LogLevel);
461+
} else {
462+
Base = std::make_unique<StreamLogger>(OS, LogLevel);
463+
}
464+
465+
if (LogPrefix.empty())
466+
return Base;
467+
class PrefixedLogger : public Logger {
468+
std::string LogPrefix;
469+
std::unique_ptr<Logger> Base;
470+
422471
public:
423-
using StreamLogger::StreamLogger;
472+
PrefixedLogger(llvm::StringRef LogPrefix, std::unique_ptr<Logger> Base)
473+
: LogPrefix(LogPrefix.str()), Base(std::move(Base)) {}
424474
void log(Level L, const char *Fmt,
425475
const llvm::formatv_object_base &Message) override {
426-
if (Context::current().get(CurrentRequest) == nullptr ||
427-
llvm::StringRef(Fmt).startswith("[public]"))
428-
return StreamLogger::log(L, Fmt, Message);
429-
if (L >= Error)
430-
return StreamLogger::log(L, Fmt, llvm::formatv("[redacted] {0}", Fmt));
476+
Base->log(L, Fmt, llvm::formatv("[{0}] {1}", LogPrefix, Message));
431477
}
432478
};
433-
return std::make_unique<RedactedLogger>(OS, LogLevel);
479+
return std::make_unique<PrefixedLogger>(LogPrefix, std::move(Base));
434480
}
435481

436482
} // namespace
@@ -454,7 +500,7 @@ int main(int argc, char *argv[]) {
454500
llvm::errs().SetBuffered();
455501
// Don't flush stdout when logging for thread safety.
456502
llvm::errs().tie(nullptr);
457-
auto Logger = makeLogger(llvm::errs());
503+
auto Logger = makeLogger(LogPrefix.getValue(), llvm::errs());
458504
clang::clangd::LoggingSession LoggingSession(*Logger);
459505

460506
llvm::Optional<llvm::raw_fd_ostream> TracerStream;

clang-tools-extra/clangd/support/Path.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace clangd {
1313

1414
#ifdef CLANGD_PATH_CASE_INSENSITIVE
1515
std::string maybeCaseFoldPath(PathRef Path) { return Path.lower(); }
16-
bool pathEqual(PathRef A, PathRef B) { return A.equals_lower(B); }
16+
bool pathEqual(PathRef A, PathRef B) { return A.equals_insensitive(B); }
1717
#else // NOT CLANGD_PATH_CASE_INSENSITIVE
1818
std::string maybeCaseFoldPath(PathRef Path) { return Path.str(); }
1919
bool pathEqual(PathRef A, PathRef B) { return A == B; }
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# RUN: rm -rf %t
2+
# RUN: clangd-indexer %S/Inputs/Source.cpp > %t.idx
3+
# RUN: %python %S/pipeline_helper.py --input-file-name=%s --server-arg=--log=verbose --server-arg=-log-prefix=test-prefix --server-log=%t.log --project-root=%S --index-file=%t.idx > /dev/null
4+
# RUN: FileCheck %s < %t.log
5+
# REQUIRES: clangd-remote-index
6+
7+
# CHECK: [test-prefix] Server listening on
8+
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
9+
---
10+
{"jsonrpc":"2.0","id":1,"method":"workspace/symbol","params":{"query":"gFoo"}}
11+
# CHECK: [test-prefix] <<< FuzzyFindRequest
12+
# CHECK: [test-prefix] >>> FuzzyFindReply
13+
# CHECK: [test-prefix] [public] request v1/FuzzyFind
14+
---
15+
{"jsonrpc":"2.0","id":4,"method":"shutdown"}
16+
---
17+
{"jsonrpc":"2.0","method":"exit"}
18+

0 commit comments

Comments
 (0)