Skip to content

Commit cafca68

Browse files
Merge branch 'llvm:main' into cfi-show
2 parents 7e0306e + 988ab5a commit cafca68

File tree

204 files changed

+110689
-1153
lines changed

Some content is hidden

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

204 files changed

+110689
-1153
lines changed

.ci/metrics/metrics.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
# by trial and error).
7171
GRAFANA_METRIC_MAX_AGE_MN = 120
7272

73+
7374
@dataclass
7475
class JobMetrics:
7576
job_name: str
@@ -243,6 +244,7 @@ def clean_up_libcxx_job_name(old_name: str) -> str:
243244
new_name = stage + "_" + remainder
244245
return new_name
245246

247+
246248
def github_get_metrics(
247249
github_repo: github.Repository, last_workflows_seen_as_completed: set[int]
248250
) -> tuple[list[JobMetrics], int]:

.ci/metrics/metrics_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,5 +409,6 @@ def test_clean_up_libcxx_job_name(self):
409409
out_name4 = metrics.clean_up_libcxx_job_name(bad_name)
410410
self.assertEqual(out_name4, bad_name)
411411

412+
412413
if __name__ == "__main__":
413414
unittest.main()

clang-tools-extra/clangd/Config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ struct Config {
174174
struct {
175175
/// Whether hover show a.k.a type.
176176
bool ShowAKA = true;
177+
/// Limit the number of characters returned when hovering a macro;
178+
/// 0 is no limit.
179+
uint32_t MacroContentsLimit = 2048;
177180
} Hover;
178181

179182
struct {

clang-tools-extra/clangd/ConfigCompile.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,12 @@ struct FragmentCompiler {
727727
C.Hover.ShowAKA = ShowAKA;
728728
});
729729
}
730+
if (F.MacroContentsLimit) {
731+
Out.Apply.push_back(
732+
[Limit(**F.MacroContentsLimit)](const Params &, Config &C) {
733+
C.Hover.MacroContentsLimit = Limit;
734+
});
735+
}
730736
}
731737

732738
void compile(Fragment::InlayHintsBlock &&F) {

clang-tools-extra/clangd/ConfigFragment.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ struct Fragment {
361361
struct HoverBlock {
362362
/// Whether hover show a.k.a type.
363363
std::optional<Located<bool>> ShowAKA;
364+
/// Limit the number of characters returned when hovering a macro.
365+
std::optional<Located<uint32_t>> MacroContentsLimit;
364366
};
365367
HoverBlock Hover;
366368

clang-tools-extra/clangd/ConfigYAML.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ class Parser {
264264
if (auto ShowAKA = boolValue(N, "ShowAKA"))
265265
F.ShowAKA = *ShowAKA;
266266
});
267+
Dict.handle("MacroContentsLimit", [&](Node &N) {
268+
if (auto MacroContentsLimit = uint32Value(N, "MacroContentsLimit"))
269+
F.MacroContentsLimit = *MacroContentsLimit;
270+
});
267271
Dict.parse(N);
268272
}
269273

clang-tools-extra/clangd/Hover.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,9 @@ HoverInfo getHoverContents(const DefinedMacro &Macro, const syntax::Token &Tok,
794794
for (const auto &ExpandedTok : Expansion->Expanded) {
795795
ExpansionText += ExpandedTok.text(SM);
796796
ExpansionText += " ";
797-
if (ExpansionText.size() > 2048) {
797+
const Config &Cfg = Config::current();
798+
const size_t Limit = static_cast<size_t>(Cfg.Hover.MacroContentsLimit);
799+
if (Limit && ExpansionText.size() > Limit) {
798800
ExpansionText.clear();
799801
break;
800802
}

clang-tools-extra/clangd/ModulesBuilder.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,10 @@ buildModuleFile(llvm::StringRef ModuleName, PathRef ModuleUnitFileName,
333333

334334
return llvm::createStringError(
335335
llvm::formatv("Failed to compile {0}. Use '--log=verbose' to view "
336-
"detailed failure reasons.",
336+
"detailed failure reasons. It is helpful to use "
337+
"'--debug-modules-builder' flag to keep the clangd's "
338+
"built module files to reproduce the failure for "
339+
"debugging. Remember to remove them after debugging.",
337340
ModuleUnitFileName));
338341
}
339342

clang-tools-extra/clangd/SemanticSelection.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,8 @@ llvm::Expected<std::vector<FoldingRange>> getFoldingRanges(ParsedAST &AST) {
175175
return collectFoldingRanges(SyntaxTree, TM);
176176
}
177177

178-
// FIXME( usaxena95): Collect PP conditional regions, includes and other code
179-
// regions (e.g. public/private/protected sections of classes, control flow
180-
// statement bodies).
178+
// FIXME( usaxena95): Collect includes and other code regions (e.g.
179+
// public/private/protected sections of classes, control flow statement bodies).
181180
// Related issue: https://github.com/clangd/clangd/issues/310
182181
llvm::Expected<std::vector<FoldingRange>>
183182
getFoldingRanges(const std::string &Code, bool LineFoldingOnly) {
@@ -186,12 +185,6 @@ getFoldingRanges(const std::string &Code, bool LineFoldingOnly) {
186185
auto DirectiveStructure = DirectiveTree::parse(OrigStream);
187186
chooseConditionalBranches(DirectiveStructure, OrigStream);
188187

189-
// FIXME: Provide ranges in the disabled-PP regions as well.
190-
auto Preprocessed = DirectiveStructure.stripDirectives(OrigStream);
191-
192-
auto ParseableStream = cook(Preprocessed, genericLangOpts());
193-
pairBrackets(ParseableStream);
194-
195188
std::vector<FoldingRange> Result;
196189
auto AddFoldingRange = [&](Position Start, Position End,
197190
llvm::StringLiteral Kind) {
@@ -220,7 +213,32 @@ getFoldingRanges(const std::string &Code, bool LineFoldingOnly) {
220213
auto EndPosition = [&](const Token &T) {
221214
return offsetToPosition(Code, EndOffset(T));
222215
};
216+
217+
// Preprocessor directives
218+
auto PPRanges = pairDirectiveRanges(DirectiveStructure, OrigStream);
219+
for (const auto &R : PPRanges) {
220+
auto BTok = OrigStream.tokens()[R.Begin];
221+
auto ETok = OrigStream.tokens()[R.End];
222+
if (ETok.Kind == tok::eof)
223+
continue;
224+
if (BTok.Line >= ETok.Line)
225+
continue;
226+
227+
Position Start = EndPosition(BTok);
228+
Position End = StartPosition(ETok);
229+
if (LineFoldingOnly)
230+
End.line--;
231+
AddFoldingRange(Start, End, FoldingRange::REGION_KIND);
232+
}
233+
234+
// FIXME: Provide ranges in the disabled-PP regions as well.
235+
auto Preprocessed = DirectiveStructure.stripDirectives(OrigStream);
236+
237+
auto ParseableStream = cook(Preprocessed, genericLangOpts());
238+
pairBrackets(ParseableStream);
239+
223240
auto Tokens = ParseableStream.tokens();
241+
224242
// Brackets.
225243
for (const auto &Tok : Tokens) {
226244
if (auto *Paired = Tok.pair()) {
@@ -240,6 +258,7 @@ getFoldingRanges(const std::string &Code, bool LineFoldingOnly) {
240258
return OriginalToken(T).Length >= 2 &&
241259
Code.substr(StartOffset(T), 2) == "/*";
242260
};
261+
243262
// Multi-line comments.
244263
for (auto *T = Tokens.begin(); T != Tokens.end();) {
245264
if (T->Kind != tok::comment) {

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,5 +356,62 @@ TokenStream DirectiveTree::stripDirectives(const TokenStream &In) const {
356356
return Out;
357357
}
358358

359+
namespace {
360+
class RangePairer {
361+
std::vector<Token::Range> &Ranges;
362+
363+
public:
364+
RangePairer(std::vector<Token::Range> &Ranges) : Ranges(Ranges) {}
365+
366+
void walk(const DirectiveTree &T) {
367+
for (const auto &C : T.Chunks)
368+
std::visit(*this, C);
369+
}
370+
371+
void operator()(const DirectiveTree::Code &C) {}
372+
373+
void operator()(const DirectiveTree::Directive &) {}
374+
375+
void operator()(const DirectiveTree::Conditional &C) {
376+
Token::Range Range;
377+
Token::Index Last;
378+
auto First = true;
379+
for (const auto &[Directive, _] : C.Branches) {
380+
if (First) {
381+
First = false;
382+
} else {
383+
Range = {Last, Directive.Tokens.Begin};
384+
Ranges.push_back(Range);
385+
}
386+
Last = Directive.Tokens.Begin;
387+
}
388+
389+
if (C.End.Kind != tok::pp_not_keyword) {
390+
Range = {Last, C.End.Tokens.Begin};
391+
Ranges.push_back(Range);
392+
}
393+
394+
for (const auto &[_, SubTree] : C.Branches)
395+
walk(SubTree);
396+
}
397+
};
398+
} // namespace
399+
400+
std::vector<Token::Range> pairDirectiveRanges(const DirectiveTree &Tree,
401+
const TokenStream &Code) {
402+
std::vector<Token::Range> Ranges;
403+
RangePairer(Ranges).walk(Tree);
404+
405+
// Transform paired ranges to start with last token in its logical line
406+
for (auto &R : Ranges) {
407+
const Token *Tok = &Code.tokens()[R.Begin + 1];
408+
while (Tok->Kind != tok::eof && !Tok->flag(LexFlags::StartsPPLine))
409+
++Tok;
410+
Tok = Tok - 1;
411+
R.Begin = Tok->OriginalIndex;
412+
}
413+
return Ranges;
414+
}
415+
359416
} // namespace clangd
360417
} // namespace clang

0 commit comments

Comments
 (0)