[clang] [clang][ast]: Add DynamicAllocLValue and TypeInfoLValue support to APValue::dump(). (PR #135178)

via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 11 07:21:42 PDT 2025


YLChenZ wrote:

> I don't think we can test `DynamicAllocLValue` like this, since we can't save it in the `APValue` for an initialized global. You'll have to add a call to `dump()` e.g. like:
> 
> ```diff
> diff --git i/clang/lib/AST/ExprConstant.cpp w/clang/lib/AST/ExprConstant.cpp
> index d1cc722fb794..df52ff82ea2a 100644
> --- i/clang/lib/AST/ExprConstant.cpp
> +++ w/clang/lib/AST/ExprConstant.cpp
> @@ -17087,6 +17087,8 @@ bool Expr::EvaluateAsInitializer(APValue &Value, const ASTContext &Ctx,
>          return false;
>      }
> 
> +    Value.dump();
> +
>      // At this point, any lifetime-extended temporaries are completely
>      // initialized.
>      Info.performLifetimeExtension();
> ```
> 
> then you can compile
> 
> ```c++
> constexpr int *m = new int(12);
> ```
> 
> to reproduce it.

Okay, I got it. Already reproduced the crash.
```
lambda at ubuntu22:~/test$ clang++ -std=c++20 -Xclang -ast-dump -fsyntax-only DAtest.cpp
LValue Base=DynamicAllocLValue, Null=0, Offset=0, HasPath=1, PathLength=0, Path=()
DAtest.cpp:1:16: error: constexpr variable 'm' must be initialized by a constant expression
    1 | constexpr int *m = new int(42);
      |                ^   ~~~~~~~~~~~
DAtest.cpp:1:16: note: pointer to heap-allocated object is not a constant expression
DAtest.cpp:1:20: note: heap allocation performed here
    1 | constexpr int *m = new int(42);
      |                    ^
LValue Base=DynamicAllocLValue, Null=0, Offset=0, HasPath=1, PathLength=0, Path=()
```


https://github.com/llvm/llvm-project/pull/135178


More information about the cfe-commits mailing list