Skip to content

Commit e17e513

Browse files
committed
Merge from 'master' to 'sycl-web' (#2)
CONFLICT (content): Merge conflict in clang/lib/AST/DeclPrinter.cpp
2 parents e02bb59 + 86e50af commit e17e513

File tree

1,007 files changed

+34217
-17612
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,007 files changed

+34217
-17612
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static std::string getExprAsString(const clang::Expr &E,
7676
Text.erase(
7777
llvm::remove_if(
7878
Text,
79-
[](char C) { return std::isspace(static_cast<unsigned char>(C)); }),
79+
[](char C) { return llvm::isSpace(static_cast<unsigned char>(C)); }),
8080
Text.end());
8181
return Text;
8282
}

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,31 @@ void SignedCharMisuseCheck::registerMatchers(MatchFinder *Finder) {
102102
.bind("comparison");
103103

104104
Finder->addMatcher(CompareOperator, this);
105+
106+
// Catch array subscripts with signed char -> integer conversion.
107+
// Matcher for C arrays.
108+
const auto CArraySubscript =
109+
arraySubscriptExpr(hasIndex(SignedCharCastExpr)).bind("arraySubscript");
110+
111+
Finder->addMatcher(CArraySubscript, this);
112+
113+
// Matcher for std arrays.
114+
const auto STDArraySubscript =
115+
cxxOperatorCallExpr(
116+
hasOverloadedOperatorName("[]"),
117+
hasArgument(0, hasType(cxxRecordDecl(hasName("::std::array")))),
118+
hasArgument(1, SignedCharCastExpr))
119+
.bind("arraySubscript");
120+
121+
Finder->addMatcher(STDArraySubscript, this);
105122
}
106123

107124
void SignedCharMisuseCheck::check(const MatchFinder::MatchResult &Result) {
108125
const auto *SignedCastExpression =
109126
Result.Nodes.getNodeAs<ImplicitCastExpr>("signedCastExpression");
127+
const auto *IntegerType = Result.Nodes.getNodeAs<QualType>("integerType");
128+
assert(SignedCastExpression);
129+
assert(IntegerType);
110130

111131
// Ignore the match if we know that the signed char's value is not negative.
112132
// The potential misinterpretation happens for negative values only.
@@ -135,14 +155,17 @@ void SignedCharMisuseCheck::check(const MatchFinder::MatchResult &Result) {
135155

136156
diag(Comparison->getBeginLoc(),
137157
"comparison between 'signed char' and 'unsigned char'");
138-
} else if (const auto *IntegerType =
139-
Result.Nodes.getNodeAs<QualType>("integerType")) {
158+
} else if (Result.Nodes.getNodeAs<Expr>("arraySubscript")) {
159+
diag(SignedCastExpression->getBeginLoc(),
160+
"'signed char' to %0 conversion in array subscript; "
161+
"consider casting to 'unsigned char' first.")
162+
<< *IntegerType;
163+
} else {
140164
diag(SignedCastExpression->getBeginLoc(),
141165
"'signed char' to %0 conversion; "
142166
"consider casting to 'unsigned char' first.")
143167
<< *IntegerType;
144-
} else
145-
llvm_unreachable("Unexpected match");
168+
}
146169
}
147170

148171
} // namespace bugprone

clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "clang/AST/RecursiveASTVisitor.h"
1313
#include "clang/ASTMatchers/ASTMatchFinder.h"
1414
#include "clang/Tooling/FixIt.h"
15+
#include "llvm/ADT/StringExtras.h"
1516

1617
#include <cctype>
1718

@@ -356,10 +357,10 @@ bool UseTrailingReturnTypeCheck::keepSpecifiers(
356357
unsigned int TOffsetInRT = TOffset - ReturnTypeBeginOffset - DeletedChars;
357358
unsigned int TLengthWithWS = CT.T.getLength();
358359
while (TOffsetInRT + TLengthWithWS < ReturnType.size() &&
359-
std::isspace(ReturnType[TOffsetInRT + TLengthWithWS]))
360+
llvm::isSpace(ReturnType[TOffsetInRT + TLengthWithWS]))
360361
TLengthWithWS++;
361362
std::string Specifier = ReturnType.substr(TOffsetInRT, TLengthWithWS);
362-
if (!std::isspace(Specifier.back()))
363+
if (!llvm::isSpace(Specifier.back()))
363364
Specifier.push_back(' ');
364365
Auto.insert(Auto.size() - InitialAutoLength, Specifier);
365366
ReturnType.erase(TOffsetInRT, TLengthWithWS);
@@ -459,7 +460,7 @@ void UseTrailingReturnTypeCheck::check(const MatchFinder::MatchResult &Result) {
459460
ReturnTypeEnd.getLocWithOffset(1)),
460461
SM, LangOpts);
461462
bool NeedSpaceAfterAuto =
462-
CharAfterReturnType.empty() || !std::isspace(CharAfterReturnType[0]);
463+
CharAfterReturnType.empty() || !llvm::isSpace(CharAfterReturnType[0]);
463464

464465
std::string Auto = NeedSpaceAfterAuto ? "auto " : "auto";
465466
std::string ReturnType =

clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ TransformerClangTidyCheck::TransformerClangTidyCheck(
3030
const OptionsView &)>
3131
MakeRule,
3232
StringRef Name, ClangTidyContext *Context)
33-
: ClangTidyCheck(Name, Context), Rule(MakeRule(getLangOpts(), Options)) {
33+
: ClangTidyCheck(Name, Context), Rule(MakeRule(getLangOpts(), Options)),
34+
IncludeStyle(Options.getLocalOrGlobal("IncludeStyle",
35+
IncludeSorter::getMapping(),
36+
IncludeSorter::IS_LLVM)) {
3437
if (Rule)
3538
assert(llvm::all_of(Rule->Cases, hasExplanation) &&
3639
"clang-tidy checks must have an explanation by default;"
@@ -40,7 +43,10 @@ TransformerClangTidyCheck::TransformerClangTidyCheck(
4043
TransformerClangTidyCheck::TransformerClangTidyCheck(RewriteRule R,
4144
StringRef Name,
4245
ClangTidyContext *Context)
43-
: ClangTidyCheck(Name, Context), Rule(std::move(R)) {
46+
: ClangTidyCheck(Name, Context), Rule(std::move(R)),
47+
IncludeStyle(Options.getLocalOrGlobal("IncludeStyle",
48+
IncludeSorter::getMapping(),
49+
IncludeSorter::IS_LLVM)) {
4450
assert(llvm::all_of(Rule->Cases, hasExplanation) &&
4551
"clang-tidy checks must have an explanation by default;"
4652
" explicitly provide an empty explanation if none is desired");
@@ -53,8 +59,8 @@ void TransformerClangTidyCheck::registerPPCallbacks(
5359
if (Rule && llvm::any_of(Rule->Cases, [](const RewriteRule::Case &C) {
5460
return !C.AddedIncludes.empty();
5561
})) {
56-
Inserter = std::make_unique<IncludeInserter>(
57-
SM, getLangOpts(), utils::IncludeSorter::IS_LLVM);
62+
Inserter =
63+
std::make_unique<IncludeInserter>(SM, getLangOpts(), IncludeStyle);
5864
PP->addPPCallbacks(Inserter->CreatePPCallbacks());
5965
}
6066
}

clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_TRANSFORMER_CLANG_TIDY_CHECK_H
1111

1212
#include "../ClangTidy.h"
13-
#include "../utils/IncludeInserter.h"
13+
#include "IncludeInserter.h"
14+
#include "IncludeSorter.h"
1415
#include "clang/ASTMatchers/ASTMatchFinder.h"
1516
#include "clang/Frontend/CompilerInstance.h"
1617
#include "clang/Tooling/Transformer/Transformer.h"
@@ -31,6 +32,13 @@ namespace utils {
3132
// MyCheck(StringRef Name, ClangTidyContext *Context)
3233
// : TransformerClangTidyCheck(MyCheckAsRewriteRule, Name, Context) {}
3334
// };
35+
//
36+
// `TransformerClangTidyCheck` recognizes this clang-tidy option:
37+
//
38+
// * IncludeStyle. A string specifying which file naming convention is used by
39+
// the source code, 'llvm' or 'google'. Default is 'llvm'. The naming
40+
// convention influences how canonical headers are distinguished from other
41+
// includes.
3442
class TransformerClangTidyCheck : public ClangTidyCheck {
3543
public:
3644
// \p MakeRule generates the rewrite rule to be used by the check, based on
@@ -61,7 +69,8 @@ class TransformerClangTidyCheck : public ClangTidyCheck {
6169

6270
private:
6371
Optional<transformer::RewriteRule> Rule;
64-
std::unique_ptr<clang::tidy::utils::IncludeInserter> Inserter;
72+
const IncludeSorter::IncludeStyle IncludeStyle;
73+
std::unique_ptr<IncludeInserter> Inserter;
6574
};
6675

6776
} // namespace utils

clang-tools-extra/clangd/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ add_clang_library(clangDaemon
4444
FileDistance.cpp
4545
Format.cpp
4646
FS.cpp
47-
FormattedString.cpp
4847
FuzzyMatch.cpp
4948
GlobalCompilationDatabase.cpp
5049
Headers.cpp

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "ClangdLSPServer.h"
1010
#include "Diagnostics.h"
1111
#include "DraftStore.h"
12-
#include "FormattedString.h"
1312
#include "GlobalCompilationDatabase.h"
1413
#include "Protocol.h"
1514
#include "SemanticHighlighting.h"
@@ -43,6 +42,11 @@ namespace clang {
4342
namespace clangd {
4443
namespace {
4544

45+
// Tracks end-to-end latency of high level lsp calls. Measurements are in
46+
// seconds.
47+
constexpr trace::Metric LSPLatency("lsp_latency", trace::Metric::Distribution,
48+
"method_name");
49+
4650
// LSP defines file versions as numbers that increase.
4751
// ClangdServer treats them as opaque and therefore uses strings instead.
4852
std::string encodeVersion(int64_t LSPVersion) {
@@ -185,7 +189,7 @@ class ClangdLSPServer::MessageHandler : public Transport::MessageHandler {
185189
WithContext HandlerContext(handlerContext());
186190
// Calls can be canceled by the client. Add cancellation context.
187191
WithContext WithCancel(cancelableRequestContext(ID));
188-
trace::Span Tracer(Method);
192+
trace::Span Tracer(Method, LSPLatency);
189193
SPAN_ATTACH(Tracer, "Params", Params);
190194
ReplyOnce Reply(ID, Method, &Server, Tracer.Args);
191195
log("<-- {0}({1})", Method, ID);
@@ -297,7 +301,7 @@ class ClangdLSPServer::MessageHandler : public Transport::MessageHandler {
297301
elog("Failed to decode {0} request.", Method);
298302
return;
299303
}
300-
trace::Span Tracer(Method);
304+
trace::Span Tracer(Method, LSPLatency);
301305
SPAN_ATTACH(Tracer, "Params", RawParams);
302306
(Server.*Handler)(P);
303307
};
@@ -1290,7 +1294,7 @@ void ClangdLSPServer::onSemanticTokens(const SemanticTokensParams &Params,
12901294
Result.tokens = toSemanticTokens(*HT);
12911295
{
12921296
std::lock_guard<std::mutex> Lock(SemanticTokensMutex);
1293-
auto& Last = LastSemanticTokens[File];
1297+
auto &Last = LastSemanticTokens[File];
12941298

12951299
Last.tokens = Result.tokens;
12961300
increment(Last.resultId);
@@ -1315,7 +1319,7 @@ void ClangdLSPServer::onSemanticTokensEdits(
13151319
SemanticTokensOrEdits Result;
13161320
{
13171321
std::lock_guard<std::mutex> Lock(SemanticTokensMutex);
1318-
auto& Last = LastSemanticTokens[File];
1322+
auto &Last = LastSemanticTokens[File];
13191323

13201324
if (PrevResultID == Last.resultId) {
13211325
Result.edits = diffTokens(Last.tokens, Toks);

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "CodeComplete.h"
1111
#include "FindSymbols.h"
1212
#include "Format.h"
13-
#include "FormattedString.h"
1413
#include "HeaderSourceSwitch.h"
1514
#include "Headers.h"
1615
#include "ParsedAST.h"
@@ -27,6 +26,7 @@
2726
#include "refactor/Rename.h"
2827
#include "refactor/Tweak.h"
2928
#include "support/Logger.h"
29+
#include "support/Markup.h"
3030
#include "support/Trace.h"
3131
#include "clang/Format/Format.h"
3232
#include "clang/Frontend/CompilerInstance.h"
@@ -43,6 +43,7 @@
4343
#include "llvm/Support/Error.h"
4444
#include "llvm/Support/FileSystem.h"
4545
#include "llvm/Support/Path.h"
46+
#include "llvm/Support/ScopedPrinter.h"
4647
#include "llvm/Support/raw_ostream.h"
4748
#include <algorithm>
4849
#include <future>
@@ -368,6 +369,9 @@ void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
368369
auto Action = [File = File.str(), NewName = NewName.str(), Pos, Opts,
369370
CB = std::move(CB), Snapshot = std::move(Snapshot),
370371
this](llvm::Expected<InputsAndAST> InpAST) mutable {
372+
// Tracks number of files edited per invocation.
373+
static constexpr trace::Metric RenameFiles("rename_files",
374+
trace::Metric::Distribution);
371375
if (!InpAST)
372376
return CB(InpAST.takeError());
373377
auto GetDirtyBuffer =
@@ -393,6 +397,7 @@ void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
393397
if (Err)
394398
return CB(std::move(Err));
395399
}
400+
RenameFiles.record(Edits->size());
396401
return CB(std::move(*Edits));
397402
};
398403
WorkScheduler.runWithAST("Rename", File, std::move(Action));
@@ -422,6 +427,9 @@ tweakSelection(const Range &Sel, const InputsAndAST &AST) {
422427

423428
void ClangdServer::enumerateTweaks(PathRef File, Range Sel,
424429
Callback<std::vector<TweakRef>> CB) {
430+
// Tracks number of times a tweak has been offered.
431+
static constexpr trace::Metric TweakAvailable(
432+
"tweak_available", trace::Metric::Counter, "tweak_id");
425433
auto Action = [File = File.str(), Sel, CB = std::move(CB),
426434
this](Expected<InputsAndAST> InpAST) mutable {
427435
if (!InpAST)
@@ -439,6 +447,7 @@ void ClangdServer::enumerateTweaks(PathRef File, Range Sel,
439447
for (auto &T : prepareTweaks(*Sel, Filter)) {
440448
Res.push_back({T->id(), T->title(), T->intent()});
441449
PreparedTweaks.insert(T->id());
450+
TweakAvailable.record(1, T->id());
442451
}
443452
}
444453

@@ -451,6 +460,10 @@ void ClangdServer::enumerateTweaks(PathRef File, Range Sel,
451460

452461
void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
453462
Callback<Tweak::Effect> CB) {
463+
// Tracks number of times a tweak has been applied.
464+
static constexpr trace::Metric TweakAttempt(
465+
"tweak_attempt", trace::Metric::Counter, "tweak_id");
466+
TweakAttempt.record(1, TweakID);
454467
auto Action =
455468
[File = File.str(), Sel, TweakID = TweakID.str(), CB = std::move(CB),
456469
FS = FSProvider.getFileSystem()](Expected<InputsAndAST> InpAST) mutable {

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include "../clang-tidy/ClangTidyOptions.h"
1313
#include "CodeComplete.h"
14-
#include "FormattedString.h"
1514
#include "GlobalCompilationDatabase.h"
1615
#include "Hover.h"
1716
#include "Protocol.h"

clang-tools-extra/clangd/CodeComplete.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETE_H
1616
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETE_H
1717

18-
#include "FormattedString.h"
1918
#include "Headers.h"
2019
#include "Protocol.h"
2120
#include "Quality.h"
2221
#include "index/Index.h"
2322
#include "index/Symbol.h"
2423
#include "index/SymbolOrigin.h"
2524
#include "support/Logger.h"
25+
#include "support/Markup.h"
2626
#include "support/Path.h"
2727
#include "clang/Sema/CodeCompleteConsumer.h"
2828
#include "clang/Sema/CodeCompleteOptions.h"
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
#define CLANGD_BUILD_XPC @CLANGD_BUILD_XPC@
2-
#define CLANGD_ENABLE_REMOTE @CLANGD_ENABLE_REMOTE@

clang-tools-extra/clangd/Headers.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ class RecordHeaders : public PPCallbacks {
3838
if (isInsideMainFile(HashLoc, SM)) {
3939
Out->MainFileIncludes.emplace_back();
4040
auto &Inc = Out->MainFileIncludes.back();
41-
Inc.R = halfOpenToRange(SM, FilenameRange);
4241
Inc.Written =
4342
(IsAngled ? "<" + FileName + ">" : "\"" + FileName + "\"").str();
4443
Inc.Resolved = std::string(File ? File->tryGetRealPathName() : "");
4544
Inc.HashOffset = SM.getFileOffset(HashLoc);
45+
Inc.HashLine =
46+
SM.getLineNumber(SM.getFileID(HashLoc), Inc.HashOffset) - 1;
4647
Inc.FileKind = FileKind;
4748
Inc.Directive = IncludeTok.getIdentifierInfo()->getPPKeywordID();
4849
}
@@ -228,8 +229,8 @@ IncludeInserter::insert(llvm::StringRef VerbatimHeader) const {
228229

229230
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Inclusion &Inc) {
230231
return OS << Inc.Written << " = "
231-
<< (!Inc.Resolved.empty() ? Inc.Resolved : "[unresolved]") << " at "
232-
<< Inc.R;
232+
<< (!Inc.Resolved.empty() ? Inc.Resolved : "[unresolved]")
233+
<< " at line" << Inc.HashLine;
233234
}
234235

235236
} // namespace clangd

clang-tools-extra/clangd/Headers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ llvm::SmallVector<llvm::StringRef, 1> getRankedIncludes(const Symbol &Sym);
5252

5353
// An #include directive that we found in the main file.
5454
struct Inclusion {
55-
Range R; // Inclusion range.
5655
tok::PPKeywordKind Directive; // Directive used for inclusion, e.g. import
5756
std::string Written; // Inclusion name as written e.g. <vector>.
5857
Path Resolved; // Resolved path of included file. Empty if not resolved.
5958
unsigned HashOffset = 0; // Byte offset from start of file to #.
59+
int HashLine = 0; // Line number containing the directive, 0-indexed.
6060
SrcMgr::CharacteristicKind FileKind = SrcMgr::C_User;
6161
};
6262
llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Inclusion &);

0 commit comments

Comments
 (0)