<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/96965>96965</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang doesn't emit `DW_TAG_const_expr` for `constexpr` variables.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mvanotti
</td>
</tr>
</table>
<pre>
When declaring a C++ variable as `constexpr`, clang doesn't emit `DW_AT_const_expr` inside the `DW_TAG_variable`.
See the following program for example:
```c++
#include <stddef.h>
constexpr size_t kPageSize = 0x1000;
int main(void) {
__asm__ volatile("" ::"r"(kPageSize));
return 0;
}
```
Compiled with:
```shell
$ clang++ -Wall -Wextra -pedantic -std=c++17 -gdwarf-5 -O0 program_with_constexpr.cc -o program_with_constexpr
```
Using `clang version 19.0.0git (https://llvm.googlesource.com/llvm-project 3809e20afc68d7d03821f0ec59b928dcf9befbf4)`
Using `$ llvm-dwarfdump ./program_with_constexpr`
```
0x00000023: DW_TAG_variable
DW_AT_name ("kPageSize")
DW_AT_type (0x0000002d "const size_t")
DW_AT_decl_file ("/home/user/test/program_with_constexpr.cc")
DW_AT_decl_line (2)
DW_AT_const_value (4096)
```
It's missing `DW_AT_const_expr`
When I compile this with gcc:
```shell
$ g++ -Wall -Wextra -pedantic -std=c++17 -gdwarf-5 -O0 program_with_constexpr.cc -o program_with_constexpr
```
```
0x0000005b: DW_TAG_variable
DW_AT_name ("kPageSize")
DW_AT_decl_file ("/home/user/test/program_with_constexpr.cc")
DW_AT_decl_line (2)
DW_AT_decl_column (0x12)
DW_AT_type (0x00000041 "const size_t")
DW_AT_const_expr (true)
DW_AT_location (DW_OP_addr 0x2008)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVs-vmzgQ_mucyyjIDEmAA4e8l82qp1ZqV--IjD2Adw2ObJOm_etXQJJNspu-HvZQC3Ew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