Skip to content

Commit 8813a4f

Browse files
committed
Only apply the restriction to __builtin_dump_struct
1 parent f15e35f commit 8813a4f

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

clang-tools-extra/clangd/InlayHints.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -590,15 +590,15 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
590590
}
591591

592592
bool dataTraverseStmtPre(Stmt *S) {
593-
// Do not show inlay hints for PseudoObjectExprs. They're never
594-
// genuine user codes.
595-
//
596-
// For example, __builtin_dump_struct would expand to a PseudoObjectExpr
597-
// that includes a couple of calls to a printf function. Printing parameter
598-
// names for that anyway would end up with duplicate parameter names (which,
599-
// however, got de-duplicated after visiting) for the printf function.
600-
if (isa<PseudoObjectExpr>(S))
601-
return false;
593+
// Do not show inlay hints for the __builtin_dump_struct, which would expand
594+
// to a PseudoObjectExpr that includes a couple of calls to a printf
595+
// function. Printing parameter names for that anyway would end up with
596+
// duplicate parameter names (which, however, got de-duplicated after
597+
// visiting) for the printf function.
598+
if (auto *POE = dyn_cast<PseudoObjectExpr>(S))
599+
if (auto *CE = dyn_cast<CallExpr>(POE->getSyntacticForm());
600+
CE && CE->getBuiltinCallee() == Builtin::BI__builtin_dump_struct)
601+
return false;
602602
return true;
603603
}
604604

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,7 @@ TEST(ParameterHints, PseudoObjectExpr) {
17291729
struct S {
17301730
__declspec(property(get=GetX, put=PutX)) int x[];
17311731
int GetX(int y, int z) { return 42 + y; }
1732-
void PutX(int y) { x = y; } // Not `x = y: y`
1732+
void PutX(int y) { x = $one[[y]]; } // FIXME: Undesired `x = y: y` for this ill-formed expression.
17331733
};
17341734
17351735
int printf(const char *Format, ...);
@@ -1738,14 +1738,17 @@ TEST(ParameterHints, PseudoObjectExpr) {
17381738
S s;
17391739
__builtin_dump_struct(&s, printf); // Not `Format: __builtin_dump_struct()`
17401740
printf($Param[["Hello, %d"]], 42); // Normal calls are not affected.
1741-
return s.x[1][2]; // Not `x[y: 1][z: 2]`
1741+
return s.x[ $two[[1]] ][ $three[[2]] ]; // `x[y: 1][z: 2]`
17421742
}
17431743
)cpp");
17441744
auto TU = TestTU::withCode(Code.code());
17451745
TU.ExtraArgs.push_back("-fms-extensions");
17461746
auto AST = TU.build();
17471747
EXPECT_THAT(inlayHints(AST, std::nullopt),
1748-
ElementsAre(HintMatcher(ExpectedHint{"Format: ", "Param"}, Code)));
1748+
ElementsAre(HintMatcher(ExpectedHint{"y: ", "one"}, Code),
1749+
HintMatcher(ExpectedHint{"Format: ", "Param"}, Code),
1750+
HintMatcher(ExpectedHint{"y: ", "two"}, Code),
1751+
HintMatcher(ExpectedHint{"z: ", "three"}, Code)));
17491752
}
17501753

17511754
TEST(ParameterHints, ArgPacksAndConstructors) {

0 commit comments

Comments
 (0)