Skip to content

Commit 4ff4085

Browse files
committed
Merge from 'main' to 'sycl-web' (148 commits)
CONFLICT (content): Merge conflict in clang/lib/Driver/Driver.cpp
2 parents a887b70 + 0a4a43c commit 4ff4085

File tree

701 files changed

+23858
-7672
lines changed

Some content is hidden

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

701 files changed

+23858
-7672
lines changed

bolt/lib/Passes/RetpolineInsertion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ BinaryFunction *createNewRetpoline(BinaryContext &BC,
168168
MCInst Return;
169169
MIB.createReturn(Return);
170170
BB2.addInstruction(Return);
171-
NewRetpoline->insertBasicBlocks(nullptr, move(NewBlocks),
171+
NewRetpoline->insertBasicBlocks(nullptr, std::move(NewBlocks),
172172
/* UpdateLayout */ true,
173173
/* UpdateCFIState */ false);
174174

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ class MacroToEnumCallbacks : public PPCallbacks {
226226
void conditionStart(const SourceLocation &Loc);
227227
void checkCondition(SourceRange ConditionRange);
228228
void checkName(const Token &MacroNameTok);
229-
void rememberExpressionName(const Token &MacroNameTok);
229+
void rememberExpressionName(const Token &Tok);
230+
void rememberExpressionTokens(ArrayRef<Token> MacroTokens);
230231
void invalidateExpressionNames();
231232
void issueDiagnostics();
232233
void warnMacroEnum(const EnumMacro &Macro) const;
@@ -302,14 +303,22 @@ void MacroToEnumCallbacks::checkName(const Token &MacroNameTok) {
302303
});
303304
}
304305

305-
void MacroToEnumCallbacks::rememberExpressionName(const Token &MacroNameTok) {
306-
std::string Id = getTokenName(MacroNameTok).str();
306+
void MacroToEnumCallbacks::rememberExpressionName(const Token &Tok) {
307+
std::string Id = getTokenName(Tok).str();
307308
auto Pos = llvm::lower_bound(ExpressionNames, Id);
308309
if (Pos == ExpressionNames.end() || *Pos != Id) {
309310
ExpressionNames.insert(Pos, Id);
310311
}
311312
}
312313

314+
void MacroToEnumCallbacks::rememberExpressionTokens(
315+
ArrayRef<Token> MacroTokens) {
316+
for (Token Tok : MacroTokens) {
317+
if (Tok.isAnyIdentifier())
318+
rememberExpressionName(Tok);
319+
}
320+
}
321+
313322
void MacroToEnumCallbacks::FileChanged(SourceLocation Loc,
314323
FileChangeReason Reason,
315324
SrcMgr::CharacteristicKind FileType,
@@ -326,6 +335,8 @@ void MacroToEnumCallbacks::FileChanged(SourceLocation Loc,
326335
CurrentFile = &Files.back();
327336
}
328337

338+
// Any defined but rejected macro is scanned for identifiers that
339+
// are to be excluded as enums.
329340
void MacroToEnumCallbacks::MacroDefined(const Token &MacroNameTok,
330341
const MacroDirective *MD) {
331342
// Include guards are never candidates for becoming an enum.
@@ -342,8 +353,12 @@ void MacroToEnumCallbacks::MacroDefined(const Token &MacroNameTok,
342353

343354
const MacroInfo *Info = MD->getMacroInfo();
344355
ArrayRef<Token> MacroTokens = Info->tokens();
345-
if (Info->isFunctionLike() || Info->isBuiltinMacro() || MacroTokens.empty())
356+
if (Info->isBuiltinMacro() || MacroTokens.empty())
357+
return;
358+
if (Info->isFunctionLike()) {
359+
rememberExpressionTokens(MacroTokens);
346360
return;
361+
}
347362

348363
// Return Lit when +Lit, -Lit or ~Lit; otherwise return Unknown.
349364
Token Unknown;
@@ -378,17 +393,22 @@ void MacroToEnumCallbacks::MacroDefined(const Token &MacroNameTok,
378393
else if (Size == 2)
379394
// It can be +Lit, -Lit or ~Lit.
380395
Tok = GetUnopArg(MacroTokens[Begin], MacroTokens[End]);
381-
else
396+
else {
382397
// Zero or too many tokens after we stripped matching parens.
398+
rememberExpressionTokens(MacroTokens);
383399
return;
400+
}
384401
} else if (MacroTokens.size() == 2) {
385402
// It can be +Lit, -Lit, or ~Lit.
386403
Tok = GetUnopArg(MacroTokens.front(), MacroTokens.back());
387404
}
388405

389406
if (!Tok.isLiteral() || isStringLiteral(Tok.getKind()) ||
390-
!isIntegralConstant(Tok))
407+
!isIntegralConstant(Tok)) {
408+
if (Tok.isAnyIdentifier())
409+
rememberExpressionName(Tok);
391410
return;
411+
}
392412

393413
if (!isConsecutiveMacro(MD))
394414
newEnum();

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ CompletionItemKind toCompletionItemKind(index::SymbolKind Kind) {
129129
case SK::TemplateTypeParm:
130130
case SK::TemplateTemplateParm:
131131
return CompletionItemKind::TypeParameter;
132+
case SK::Concept:
133+
return CompletionItemKind::Interface;
132134
}
133135
llvm_unreachable("Unhandled clang::index::SymbolKind.");
134136
}

clang-tools-extra/clangd/Protocol.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "support/Logger.h"
1616
#include "clang/Basic/LLVM.h"
1717
#include "clang/Index/IndexSymbol.h"
18+
#include "llvm/ADT/StringRef.h"
1819
#include "llvm/ADT/StringSwitch.h"
1920
#include "llvm/Support/ErrorHandling.h"
2021
#include "llvm/Support/JSON.h"
@@ -301,6 +302,8 @@ SymbolKind indexSymbolKindToSymbolKind(index::SymbolKind Kind) {
301302
case index::SymbolKind::TemplateTemplateParm:
302303
case index::SymbolKind::TemplateTypeParm:
303304
return SymbolKind::TypeParameter;
305+
case index::SymbolKind::Concept:
306+
return SymbolKind::Interface;
304307
}
305308
llvm_unreachable("invalid symbol kind");
306309
}
@@ -1316,7 +1319,7 @@ bool fromJSON(const llvm::json::Value &Params, InlayHintsParams &R,
13161319
return O && O.map("textDocument", R.textDocument) && O.map("range", R.range);
13171320
}
13181321

1319-
llvm::json::Value toJSON(InlayHintKind K) {
1322+
static llvm::StringLiteral toString(InlayHintKind K) {
13201323
switch (K) {
13211324
case InlayHintKind::ParameterHint:
13221325
return "parameter";
@@ -1328,6 +1331,8 @@ llvm::json::Value toJSON(InlayHintKind K) {
13281331
llvm_unreachable("Unknown clang.clangd.InlayHintKind");
13291332
}
13301333

1334+
llvm::json::Value toJSON(InlayHintKind K) { return toString(K); }
1335+
13311336
llvm::json::Value toJSON(const InlayHint &H) {
13321337
return llvm::json::Object{{"position", H.position},
13331338
{"range", H.range},
@@ -1343,6 +1348,10 @@ bool operator<(const InlayHint &A, const InlayHint &B) {
13431348
std::tie(B.position, B.range, B.kind, B.label);
13441349
}
13451350

1351+
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, InlayHintKind Kind) {
1352+
return OS << toString(Kind);
1353+
}
1354+
13461355
static const char *toString(OffsetEncoding OE) {
13471356
switch (OE) {
13481357
case OffsetEncoding::UTF8:

clang-tools-extra/clangd/Protocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,6 +1579,7 @@ struct InlayHint {
15791579
llvm::json::Value toJSON(const InlayHint &);
15801580
bool operator==(const InlayHint &, const InlayHint &);
15811581
bool operator<(const InlayHint &, const InlayHint &);
1582+
llvm::raw_ostream &operator<<(llvm::raw_ostream &, InlayHintKind);
15821583

15831584
struct ReferenceContext {
15841585
/// Include the declaration of the current symbol.

clang-tools-extra/clangd/Quality.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ categorize(const index::SymbolInfo &D) {
122122
case index::SymbolKind::TypeAlias:
123123
case index::SymbolKind::TemplateTypeParm:
124124
case index::SymbolKind::TemplateTemplateParm:
125+
case index::SymbolKind::Concept:
125126
return SymbolQualitySignals::Type;
126127
case index::SymbolKind::Function:
127128
case index::SymbolKind::ClassMethod:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ bool shouldCollectIncludePath(index::SymbolKind Kind) {
8888
case SK::Function:
8989
case SK::Variable:
9090
case SK::EnumConstant:
91+
case SK::Concept:
9192
return true;
9293
default:
9394
return false;

clang-tools-extra/clangd/tool/Check.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
#include "Config.h"
3131
#include "GlobalCompilationDatabase.h"
3232
#include "Hover.h"
33+
#include "InlayHints.h"
3334
#include "ParsedAST.h"
3435
#include "Preamble.h"
36+
#include "Protocol.h"
3537
#include "SourceCode.h"
3638
#include "XRefs.h"
3739
#include "index/CanonicalIncludes.h"
@@ -190,10 +192,19 @@ class Checker {
190192
return true;
191193
}
192194

195+
// Build Inlay Hints for the entire AST or the specified range
196+
void buildInlayHints(llvm::Optional<Range> LineRange) {
197+
log("Building inlay hints");
198+
auto Hints = inlayHints(*AST, LineRange);
199+
200+
for (const auto &Hint : Hints) {
201+
vlog(" {0} {1} {2}", Hint.kind, Hint.position, Hint.label);
202+
}
203+
}
204+
193205
// Run AST-based features at each token in the file.
194-
void testLocationFeatures(
195-
llvm::function_ref<bool(const Position &)> ShouldCheckLine,
196-
const bool EnableCodeCompletion) {
206+
void testLocationFeatures(llvm::Optional<Range> LineRange,
207+
const bool EnableCodeCompletion) {
197208
trace::Span Trace("testLocationFeatures");
198209
log("Testing features at each token (may be slow in large files)");
199210
auto &SM = AST->getSourceManager();
@@ -207,7 +218,7 @@ class Checker {
207218
unsigned End = Start + Tok.length();
208219
Position Pos = offsetToPosition(Inputs.Contents, Start);
209220

210-
if (!ShouldCheckLine(Pos))
221+
if (LineRange && !LineRange->contains(Pos))
211222
continue;
212223

213224
trace::Span Trace("Token");
@@ -254,8 +265,7 @@ class Checker {
254265

255266
} // namespace
256267

257-
bool check(llvm::StringRef File,
258-
llvm::function_ref<bool(const Position &)> ShouldCheckLine,
268+
bool check(llvm::StringRef File, llvm::Optional<Range> LineRange,
259269
const ThreadsafeFS &TFS, const ClangdLSPServer::Options &Opts,
260270
bool EnableCodeCompletion) {
261271
llvm::SmallString<0> FakeFile;
@@ -284,7 +294,8 @@ bool check(llvm::StringRef File,
284294
if (!C.buildCommand(TFS) || !C.buildInvocation(TFS, Contents) ||
285295
!C.buildAST())
286296
return false;
287-
C.testLocationFeatures(ShouldCheckLine, EnableCodeCompletion);
297+
C.buildInlayHints(LineRange);
298+
C.testLocationFeatures(LineRange, EnableCodeCompletion);
288299

289300
log("All checks completed, {0} errors", C.ErrCount);
290301
return C.ErrCount == 0;

clang-tools-extra/clangd/tool/ClangdMain.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ namespace clang {
6161
namespace clangd {
6262

6363
// Implemented in Check.cpp.
64-
bool check(const llvm::StringRef File,
65-
llvm::function_ref<bool(const Position &)> ShouldCheckLine,
64+
bool check(const llvm::StringRef File, llvm::Optional<Range> LineRange,
6665
const ThreadsafeFS &TFS, const ClangdLSPServer::Options &Opts,
6766
bool EnableCodeCompletion);
6867

@@ -955,8 +954,9 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
955954
return 1;
956955
}
957956
log("Entering check mode (no LSP server)");
958-
uint32_t Begin = 0, End = std::numeric_limits<uint32_t>::max();
957+
llvm::Optional<Range> CheckLineRange;
959958
if (!CheckFileLines.empty()) {
959+
uint32_t Begin = 0, End = std::numeric_limits<uint32_t>::max();
960960
StringRef RangeStr(CheckFileLines);
961961
bool ParseError = RangeStr.consumeInteger(0, Begin);
962962
if (RangeStr.empty()) {
@@ -965,19 +965,18 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
965965
ParseError |= !RangeStr.consume_front("-");
966966
ParseError |= RangeStr.consumeInteger(0, End);
967967
}
968-
if (ParseError || !RangeStr.empty()) {
969-
elog("Invalid --check-line specified. Use Begin-End format, e.g. 3-17");
968+
if (ParseError || !RangeStr.empty() || Begin <= 0 || End < Begin) {
969+
elog(
970+
"Invalid --check-lines specified. Use Begin-End format, e.g. 3-17");
970971
return 1;
971972
}
973+
CheckLineRange = Range{Position{static_cast<int>(Begin - 1), 0},
974+
Position{static_cast<int>(End), 0}};
972975
}
973-
auto ShouldCheckLine = [&](const Position &Pos) {
974-
uint32_t Line = Pos.line + 1; // Position::line is 0-based.
975-
return Line >= Begin && Line <= End;
976-
};
977976
// For now code completion is enabled any time the range is limited via
978977
// --check-lines. If it turns out to be to slow, we can introduce a
979978
// dedicated flag for that instead.
980-
return check(Path, ShouldCheckLine, TFS, Opts,
979+
return check(Path, CheckLineRange, TFS, Opts,
981980
/*EnableCodeCompletion=*/!CheckFileLines.empty())
982981
? 0
983982
: static_cast<int>(ErrorResultCode::CheckFailed);

clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3565,6 +3565,38 @@ TEST(CompletionTest, CommentParamName) {
35653565
IsEmpty());
35663566
}
35673567

3568+
TEST(CompletionTest, Concepts) {
3569+
Annotations Code(R"cpp(
3570+
template<class T>
3571+
concept A = sizeof(T) <= 8;
3572+
3573+
template<$tparam^A U>
3574+
int foo();
3575+
3576+
template<class T>
3577+
concept b = $other^A<T> && $other^sizeof(T) % 2 == 0 || $other^A<T> && sizeof(T) == 1;
3578+
3579+
$other^A<T> auto i = 19;
3580+
)cpp");
3581+
TestTU TU;
3582+
TU.Code = Code.code().str();
3583+
TU.ExtraArgs = {"-std=c++20"};
3584+
3585+
std::vector<Symbol> Syms = {conceptSym("same_as")};
3586+
for (auto P : Code.points("tparam")) {
3587+
ASSERT_THAT(completions(TU, P, Syms).Completions,
3588+
AllOf(Contains(named("A")), Contains(named("same_as")),
3589+
Contains(named("class")), Contains(named("typename"))))
3590+
<< "Completing template parameter at position " << P;
3591+
}
3592+
3593+
for (auto P : Code.points("other")) {
3594+
EXPECT_THAT(completions(TU, P, Syms).Completions,
3595+
AllOf(Contains(named("A")), Contains(named("same_as"))))
3596+
<< "Completing 'requires' expression at position " << P;
3597+
}
3598+
}
3599+
35683600
TEST(SignatureHelp, DocFormat) {
35693601
Annotations Code(R"cpp(
35703602
// Comment `with` markup.

0 commit comments

Comments
 (0)