Skip to content

Commit 077e1b8

Browse files
authored
[clang] Preserve UDL nodes in RemoveNestedImmediateInvocation (#66641)
D63960 performs a tree transformation on AST to prevent evaluating constant expressions eagerly by removing recorded immediate consteval invocations from subexpressions. (See https://reviews.llvm.org/D63960#inline-600736 for its motivation.) However, the UDL node has been replaced with a CallExpr in the default TreeTransform since ca844ab (inadvertently?). This confuses clangd as it relies on the exact AST node type to decide whether or not to present inlay hints for an expression. With regard to the fix, I think it's enough to return the UDL expression as-is during the transformation: We've bound it to temporary in its construction, and there's no ConstantExpr to visit under a UDL. Fixes #63898.
1 parent 73f8ec9 commit 077e1b8

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ Bug Fixes in This Version
325325
(`#67722 <https://github.com/llvm/llvm-project/issues/67722>`_).
326326
- Fixes a crash when instantiating a lambda with requires clause.
327327
(`#64462 <https://github.com/llvm/llvm-project/issues/64462>`_)
328+
- Fixes a regression where the ``UserDefinedLiteral`` was not properly preserved
329+
while evaluating consteval functions. (`#63898 <https://github.com/llvm/llvm-project/issues/63898>`_).
328330

329331
Bug Fixes to Compiler Builtins
330332
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaExpr.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18468,7 +18468,10 @@ static void RemoveNestedImmediateInvocation(
1846818468
DRSet.erase(cast<DeclRefExpr>(E->getCallee()->IgnoreImplicit()));
1846918469
return Base::TransformCXXOperatorCallExpr(E);
1847018470
}
18471-
/// Base::TransformInitializer skip ConstantExpr so we need to visit them
18471+
/// Base::TransformUserDefinedLiteral doesn't preserve the
18472+
/// UserDefinedLiteral node.
18473+
ExprResult TransformUserDefinedLiteral(UserDefinedLiteral *E) { return E; }
18474+
/// Base::TransformInitializer skips ConstantExpr so we need to visit them
1847218475
/// here.
1847318476
ExprResult TransformInitializer(Expr *Init, bool NotCopyInit) {
1847418477
if (!Init)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clang_cc1 -xc++ -std=c++23 -ast-dump %s | FileCheck %s
2+
3+
int inline consteval operator""_u32(unsigned long long val) {
4+
return val;
5+
}
6+
7+
void udl() {
8+
(void)(0_u32 + 1_u32);
9+
}
10+
11+
// CHECK: `-BinaryOperator {{.+}} <col:10, col:18> 'int' '+'
12+
// CHECK-NEXT: |-ConstantExpr {{.+}} <col:10> 'int'
13+
// CHECK-NEXT: | |-value: Int 0
14+
// CHECK-NEXT: | `-UserDefinedLiteral {{.+}} <col:10> 'int'
15+
// CHECK: `-ConstantExpr {{.+}} <col:18> 'int'
16+
// CHECK-NEXT: |-value: Int 1
17+
// CHECK-NEXT: `-UserDefinedLiteral {{.+}} <col:18> 'int'

0 commit comments

Comments
 (0)