Skip to content

Commit dee2ee9

Browse files
committed
Merge from 'master' to 'sycl-web' (#2)
CONFLICT (content): Merge conflict in clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
2 parents f1acb4a + 98f76ad commit dee2ee9

File tree

1,377 files changed

+114055
-27033
lines changed

Some content is hidden

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

1,377 files changed

+114055
-27033
lines changed

.github/workflows/main-branch-sync.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: main branch sync
33
on:
44
push:
55
branches:
6-
- 'master'
6+
- 'main'
77

88
jobs:
99
branch_sync:
@@ -22,4 +22,4 @@ jobs:
2222
env:
2323
LLVMBOT_TOKEN: ${{ secrets.LLVMBOT_MAIN_SYNC }}
2424
run: |
25-
git push https://[email protected]/${{ github.repository }} HEAD:main
25+
git push https://[email protected]/${{ github.repository }} HEAD:master

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,22 @@ char UnparseableEnumOptionError::ID;
2121
char UnparseableIntegerOptionError::ID;
2222

2323
std::string MissingOptionError::message() const {
24-
llvm::SmallString<128> Buffer;
25-
llvm::raw_svector_ostream Output(Buffer);
26-
Output << "option not found '" << OptionName << '\'';
24+
llvm::SmallString<128> Buffer({"option not found '", OptionName, "'"});
2725
return std::string(Buffer);
2826
}
2927

3028
std::string UnparseableEnumOptionError::message() const {
31-
llvm::SmallString<128> Buffer;
32-
llvm::raw_svector_ostream Output(Buffer);
33-
Output << "invalid configuration value '" << LookupValue << "' for option '"
34-
<< LookupName << '\'';
29+
llvm::SmallString<256> Buffer({"invalid configuration value '", LookupValue,
30+
"' for option '", LookupName, "'"});
3531
if (SuggestedValue)
36-
Output << "; did you mean '" << *SuggestedValue << "'?";
32+
Buffer.append({"; did you mean '", *SuggestedValue, "'?"});
3733
return std::string(Buffer);
3834
}
3935

4036
std::string UnparseableIntegerOptionError::message() const {
41-
llvm::SmallString<128> Buffer;
42-
llvm::raw_svector_ostream Output(Buffer);
43-
Output << "invalid configuration value '" << LookupValue << "' for option '"
44-
<< LookupName << "'; expected "
45-
<< (IsBoolean ? "a bool" : "an integer value");
37+
llvm::SmallString<256> Buffer({"invalid configuration value '", LookupValue,
38+
"' for option '", LookupName, "'; expected ",
39+
(IsBoolean ? "a bool" : "an integer value")});
4640
return std::string(Buffer);
4741
}
4842

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ void SignedCharMisuseCheck::registerMatchers(MatchFinder *Finder) {
8484
const auto UnSignedCharCastExpr =
8585
charCastExpression(false, IntegerType, "unsignedCastExpression");
8686

87-
// Catch assignments with singed char -> integer conversion.
87+
// Catch assignments with signed char -> integer conversion.
8888
const auto AssignmentOperatorExpr =
8989
expr(binaryOperator(hasOperatorName("="), hasLHS(hasType(IntegerType)),
9090
hasRHS(SignedCharCastExpr)));
9191

9292
Finder->addMatcher(AssignmentOperatorExpr, this);
9393

94-
// Catch declarations with singed char -> integer conversion.
94+
// Catch declarations with signed char -> integer conversion.
9595
const auto Declaration = varDecl(isDefinition(), hasType(IntegerType),
9696
hasInitializer(SignedCharCastExpr));
9797

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ ClangdServer::Options::operator TUScheduler::Options() const {
139139
ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
140140
const ThreadsafeFS &TFS, const Options &Opts,
141141
Callbacks *Callbacks)
142-
: ConfigProvider(Opts.ConfigProvider), TFS(TFS),
142+
: ConfigProvider(Opts.ConfigProvider), TFS(TFS), ServerCallbacks(Callbacks),
143143
DynamicIdx(Opts.BuildDynamicSymbolIndex
144144
? new FileIndex(Opts.HeavyweightDynamicSymbolIndex,
145145
Opts.CollectMainFileRefs)
@@ -829,16 +829,44 @@ Context ClangdServer::createProcessingContext(PathRef File) const {
829829
Params.Path = PosixPath.str();
830830
}
831831

832-
auto DiagnosticHandler = [](const llvm::SMDiagnostic &Diag) {
833-
if (Diag.getKind() == llvm::SourceMgr::DK_Error) {
834-
elog("config error at {0}:{1}:{2}: {3}", Diag.getFilename(),
835-
Diag.getLineNo(), Diag.getColumnNo(), Diag.getMessage());
836-
} else {
837-
log("config warning at {0}:{1}:{2}: {3}", Diag.getFilename(),
838-
Diag.getLineNo(), Diag.getColumnNo(), Diag.getMessage());
832+
llvm::StringMap<std::vector<Diag>> ReportableDiagnostics;
833+
auto ConfigDiagnosticHandler = [&](const llvm::SMDiagnostic &D) {
834+
// Ensure we create the map entry even for note diagnostics we don't report.
835+
// This means that when the file is parsed with no warnings, we'll
836+
// publish an empty set of diagnostics, clearing any the client has.
837+
auto *Reportable = D.getFilename().empty()
838+
? nullptr
839+
: &ReportableDiagnostics[D.getFilename()];
840+
switch (D.getKind()) {
841+
case llvm::SourceMgr::DK_Error:
842+
elog("config error at {0}:{1}:{2}: {3}", D.getFilename(), D.getLineNo(),
843+
D.getColumnNo(), D.getMessage());
844+
if (Reportable)
845+
Reportable->push_back(toDiag(D, Diag::ClangdConfig));
846+
break;
847+
case llvm::SourceMgr::DK_Warning:
848+
log("config warning at {0}:{1}:{2}: {3}", D.getFilename(), D.getLineNo(),
849+
D.getColumnNo(), D.getMessage());
850+
if (Reportable)
851+
Reportable->push_back(toDiag(D, Diag::ClangdConfig));
852+
break;
853+
case llvm::SourceMgr::DK_Note:
854+
case llvm::SourceMgr::DK_Remark:
855+
vlog("config note at {0}:{1}:{2}: {3}", D.getFilename(), D.getLineNo(),
856+
D.getColumnNo(), D.getMessage());
857+
break;
839858
}
840859
};
841-
Config C = ConfigProvider->getConfig(Params, DiagnosticHandler);
860+
Config C = ConfigProvider->getConfig(Params, ConfigDiagnosticHandler);
861+
// Blindly publish diagnostics for the (unopened) parsed config files.
862+
// We must avoid reporting diagnostics for *the same file* concurrently.
863+
// Source file diags are published elsewhere, but those are different files.
864+
if (!ReportableDiagnostics.empty()) {
865+
std::lock_guard<std::mutex> Lock(ConfigDiagnosticsMu);
866+
for (auto &Entry : ReportableDiagnostics)
867+
ServerCallbacks->onDiagnosticsReady(Entry.first(), /*Version=*/"",
868+
std::move(Entry.second));
869+
}
842870
return Context::current().derive(Config::Key, std::move(C));
843871
}
844872

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ class ClangdServer {
363363
config::Provider *ConfigProvider = nullptr;
364364

365365
const ThreadsafeFS &TFS;
366+
Callbacks *ServerCallbacks = nullptr;
367+
mutable std::mutex ConfigDiagnosticsMu;
366368

367369
Path ResourceDir;
368370
// The index used to look up symbols. This could be:

clang-tools-extra/clangd/ConfigProvider.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Provider::fromAncestorRelativeYAMLFiles(llvm::StringRef RelPath,
8383
const ThreadsafeFS &FS;
8484

8585
mutable std::mutex Mu;
86-
// Keys are the ancestor directory, not the actual config path within it.
86+
// Keys are the (posix-style) ancestor directory, not the config within it.
8787
// We only insert into this map, so pointers to values are stable forever.
8888
// Mutex guards the map itself, not the values (which are threadsafe).
8989
mutable llvm::StringMap<FileConfigCache> Cache;
@@ -117,6 +117,8 @@ Provider::fromAncestorRelativeYAMLFiles(llvm::StringRef RelPath,
117117
if (It == Cache.end()) {
118118
llvm::SmallString<256> ConfigPath = Ancestor;
119119
path::append(ConfigPath, RelPath);
120+
// Use native slashes for reading the file, affects diagnostics.
121+
llvm::sys::path::native(ConfigPath);
120122
It = Cache.try_emplace(Ancestor, ConfigPath.str(), Ancestor).first;
121123
}
122124
Caches.push_back(&It->second);

clang-tools-extra/clangd/ConfigProvider.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ struct Params {
4646
/// Used to report problems in parsing or interpreting a config.
4747
/// Errors reflect structurally invalid config that should be user-visible.
4848
/// Warnings reflect e.g. unknown properties that are recoverable.
49+
/// Notes are used to report files and fragments.
50+
/// (This can be used to track when previous warnings/errors have been "fixed").
4951
using DiagnosticCallback = llvm::function_ref<void(const llvm::SMDiagnostic &)>;
5052

5153
/// A chunk of configuration that has been fully analyzed and is ready to apply.

clang-tools-extra/clangd/ConfigYAML.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,16 @@ std::vector<Fragment> Fragment::parseYAML(llvm::StringRef YAML,
273273
Fragment Fragment;
274274
Fragment.Source.Manager = SM;
275275
Fragment.Source.Location = N->getSourceRange().Start;
276+
SM->PrintMessage(Fragment.Source.Location, llvm::SourceMgr::DK_Note,
277+
"Parsing config fragment");
276278
if (Parser(*SM).parse(Fragment, *N))
277279
Result.push_back(std::move(Fragment));
278280
}
279281
}
282+
SM->PrintMessage(SM->FindLocForLineAndColumn(SM->getMainFileID(), 0, 0),
283+
llvm::SourceMgr::DK_Note,
284+
"Parsed " + llvm::Twine(Result.size()) +
285+
" fragments from file");
280286
// Hack: stash the buffer in the SourceMgr to keep it alive.
281287
// SM has two entries: "main" non-owning buffer, and ignored owning buffer.
282288
SM->AddNewSourceBuffer(std::move(Buf), llvm::SMLoc());

clang-tools-extra/clangd/Diagnostics.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,32 @@ CodeAction toCodeAction(const Fix &F, const URIForFile &File) {
377377
return Action;
378378
}
379379

380+
Diag toDiag(const llvm::SMDiagnostic &D, Diag::DiagSource Source) {
381+
Diag Result;
382+
Result.Message = D.getMessage().str();
383+
switch (D.getKind()) {
384+
case llvm::SourceMgr::DK_Error:
385+
Result.Severity = DiagnosticsEngine::Error;
386+
break;
387+
case llvm::SourceMgr::DK_Warning:
388+
Result.Severity = DiagnosticsEngine::Warning;
389+
break;
390+
default:
391+
break;
392+
}
393+
Result.Source = Source;
394+
Result.AbsFile = D.getFilename().str();
395+
Result.InsideMainFile = D.getSourceMgr()->FindBufferContainingLoc(
396+
D.getLoc()) == D.getSourceMgr()->getMainFileID();
397+
if (D.getRanges().empty())
398+
Result.Range = {{D.getLineNo() - 1, D.getColumnNo()},
399+
{D.getLineNo() - 1, D.getColumnNo()}};
400+
else
401+
Result.Range = {{D.getLineNo() - 1, (int)D.getRanges().front().first},
402+
{D.getLineNo() - 1, (int)D.getRanges().front().second}};
403+
return Result;
404+
}
405+
380406
void toLSPDiags(
381407
const Diag &D, const URIForFile &File, const ClangdDiagnosticOptions &Opts,
382408
llvm::function_ref<void(clangd::Diagnostic, llvm::ArrayRef<Fix>)> OutFn) {
@@ -404,6 +430,9 @@ void toLSPDiags(
404430
case Diag::ClangTidy:
405431
Main.source = "clang-tidy";
406432
break;
433+
case Diag::ClangdConfig:
434+
Main.source = "clangd-config";
435+
break;
407436
case Diag::Unknown:
408437
break;
409438
}

clang-tools-extra/clangd/Diagnostics.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/ADT/Optional.h"
2121
#include "llvm/ADT/STLExtras.h"
2222
#include "llvm/ADT/StringSet.h"
23+
#include "llvm/Support/SourceMgr.h"
2324
#include <cassert>
2425
#include <string>
2526

@@ -86,10 +87,11 @@ struct Note : DiagBase {};
8687
struct Diag : DiagBase {
8788
std::string Name; // if ID was recognized.
8889
// The source of this diagnostic.
89-
enum {
90+
enum DiagSource {
9091
Unknown,
9192
Clang,
9293
ClangTidy,
94+
ClangdConfig,
9395
} Source = Unknown;
9496
/// Elaborate on the problem, usually pointing to a related piece of code.
9597
std::vector<Note> Notes;
@@ -98,6 +100,8 @@ struct Diag : DiagBase {
98100
};
99101
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Diag &D);
100102

103+
Diag toDiag(const llvm::SMDiagnostic &, Diag::DiagSource Source);
104+
101105
/// Conversion to LSP diagnostics. Formats the error message of each diagnostic
102106
/// to include all its notes. Notes inside main file are also provided as
103107
/// separate diagnostics with their corresponding fixits. Notes outside main

clang-tools-extra/clangd/Selection.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,24 @@ using Node = SelectionTree::Node;
3838
using ast_type_traits::DynTypedNode;
3939

4040
// Measure the fraction of selections that were enabled by recovery AST.
41-
void recordMetrics(const SelectionTree &S) {
41+
void recordMetrics(const SelectionTree &S, const LangOptions &Lang) {
42+
if (!trace::enabled())
43+
return;
44+
const char *LanguageLabel = Lang.CPlusPlus ? "C++" : Lang.ObjC ? "ObjC" : "C";
4245
static constexpr trace::Metric SelectionUsedRecovery(
43-
"selection_recovery", trace::Metric::Distribution);
44-
static constexpr trace::Metric RecoveryType("selection_recovery_type",
45-
trace::Metric::Distribution);
46+
"selection_recovery", trace::Metric::Distribution, "language");
47+
static constexpr trace::Metric RecoveryType(
48+
"selection_recovery_type", trace::Metric::Distribution, "language");
4649
const auto *Common = S.commonAncestor();
4750
for (const auto *N = Common; N; N = N->Parent) {
4851
if (const auto *RE = N->ASTNode.get<RecoveryExpr>()) {
49-
SelectionUsedRecovery.record(1); // used recovery ast.
50-
RecoveryType.record(RE->isTypeDependent() ? 0 : 1);
52+
SelectionUsedRecovery.record(1, LanguageLabel); // used recovery ast.
53+
RecoveryType.record(RE->isTypeDependent() ? 0 : 1, LanguageLabel);
5154
return;
5255
}
5356
}
5457
if (Common)
55-
SelectionUsedRecovery.record(0); // unused.
58+
SelectionUsedRecovery.record(0, LanguageLabel); // unused.
5659
}
5760

5861
// An IntervalSet maintains a set of disjoint subranges of an array.
@@ -834,7 +837,7 @@ SelectionTree::SelectionTree(ASTContext &AST, const syntax::TokenBuffer &Tokens,
834837
.printToString(SM));
835838
Nodes = SelectionVisitor::collect(AST, Tokens, PrintPolicy, Begin, End, FID);
836839
Root = Nodes.empty() ? nullptr : &Nodes.front();
837-
recordMetrics(*this);
840+
recordMetrics(*this, AST.getLangOpts());
838841
dlog("Built selection tree\n{0}", *this);
839842
}
840843

clang-tools-extra/clangd/refactor/Rename.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,10 @@ llvm::Expected<RenameResult> rename(const RenameInputs &RInputs) {
637637
if (DeclsUnderCursor.size() > 1)
638638
return makeError(ReasonToReject::AmbiguousSymbol);
639639
const auto &RenameDecl = **DeclsUnderCursor.begin();
640-
if (RenameDecl.getName() == RInputs.NewName)
640+
const auto *ID = RenameDecl.getIdentifier();
641+
if (!ID)
642+
return makeError(ReasonToReject::UnsupportedSymbol);
643+
if (ID->getName() == RInputs.NewName)
641644
return makeError(ReasonToReject::SameName);
642645
auto Invalid = checkName(RenameDecl, RInputs.NewName);
643646
if (Invalid)

clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ bool AddUsing::prepare(const Selection &Inputs) {
274274
} else if (auto *T = Node->ASTNode.get<TypeLoc>()) {
275275
if (auto E = T->getAs<ElaboratedTypeLoc>()) {
276276
QualifierToRemove = E.getQualifierLoc();
277+
if (!QualifierToRemove)
278+
return false;
277279

278280
auto SpelledTokens =
279281
TB.spelledForExpanded(TB.expandedTokens(E.getSourceRange()));
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# We specify a custom path in XDG_CONFIG_HOME, which only works on some systems.
2+
# UNSUPPORTED: system-windows
3+
# UNSUPPORTED: system-darwin
4+
5+
# RUN: rm -rf %t
6+
# RUN: mkdir -p %t/clangd
7+
8+
# Create a config file that injects a flag we can observe, and has an error.
9+
# RUN: echo 'Foo: bar' > %t/clangd/config.yaml
10+
# RUN: echo 'CompileFlags: {Add: -DFOO=BAR}' >> %t/clangd/config.yaml
11+
12+
# RUN: env XDG_CONFIG_HOME=%t clangd -lit-test -enable-config < %s | FileCheck -strict-whitespace %s
13+
14+
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
15+
---
16+
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.c","languageId":"c","text":"int x = FOO;"}}}
17+
# First, the errors from the config file.
18+
# CHECK: "method": "textDocument/publishDiagnostics",
19+
# CHECK-NEXT: "params": {
20+
# CHECK-NEXT: "diagnostics": [
21+
# CHECK-NEXT: {
22+
# CHECK-NEXT: "message": "Unknown Config key Foo",
23+
# CHECK-NEXT: "range": {
24+
# CHECK-NEXT: "end": {
25+
# CHECK-NEXT: "character": 3,
26+
# CHECK-NEXT: "line": 0
27+
# CHECK-NEXT: },
28+
# CHECK-NEXT: "start": {
29+
# CHECK-NEXT: "character": 0,
30+
# CHECK-NEXT: "line": 0
31+
# CHECK-NEXT: }
32+
# CHECK-NEXT: },
33+
# CHECK-NEXT: "severity": 2,
34+
# CHECK-NEXT: "source": "clangd-config"
35+
# CHECK-NEXT: }
36+
# CHECK-NEXT: ],
37+
# CHECK-NEXT: "uri": "file://{{.*}}/config.yaml"
38+
# CHECK-NEXT: }
39+
# Next, the error from the main file. BAR rather than FOO means we used config.
40+
# CHECK: "method": "textDocument/publishDiagnostics",
41+
# CHECK-NEXT: "params": {
42+
# CHECK-NEXT: "diagnostics": [
43+
# CHECK-NEXT: {
44+
# CHECK-NEXT: "code": "undeclared_var_use",
45+
# CHECK-NEXT: "message": "Use of undeclared identifier 'BAR'",
46+
# CHECK-NEXT: "range": {
47+
# CHECK-NEXT: "end": {
48+
# CHECK-NEXT: "character": 11,
49+
# CHECK-NEXT: "line": 0
50+
# CHECK-NEXT: },
51+
# CHECK-NEXT: "start": {
52+
# CHECK-NEXT: "character": 8,
53+
# CHECK-NEXT: "line": 0
54+
# CHECK-NEXT: }
55+
# CHECK-NEXT: },
56+
# CHECK-NEXT: "severity": 1,
57+
# CHECK-NEXT: "source": "clang"
58+
# CHECK-NEXT: }
59+
# CHECK-NEXT: ],
60+
# CHECK-NEXT: "uri": "file://{{.*}}/foo.c",
61+
# CHECK-NEXT: "version": 0
62+
# CHECK-NEXT: }
63+
---
64+
{"jsonrpc":"2.0","id":4,"method":"shutdown"}
65+
---
66+
{"jsonrpc":"2.0","method":"exit"}

0 commit comments

Comments
 (0)