<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62274>62274</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[DebubInfo]location is not right for static variable when optimization is enabled.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
debuginfo
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
chenzheng1030
</td>
</tr>
</table>
<pre>
```
static int data2 = 10;
void set1()
{
data2 = 100;
}
void set2()
{
data2 = 10;
}
int get()
{
return data2;
}
int main()
{
set2();
set1();
return get();
}
```
```
clang 1.c -O2 -g
```
```
llvm-dwarfdump -i a.out
.debug_info contents:
0x00000000: Compile Unit: length = 0x0000007e, format = DWARF32, version = 0x0005, unit_type = DW_UT_compile, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x00000082)
0x00000027: DW_TAG_variable
DW_AT_name ("data2")
DW_AT_type (0x0000003a "int")
DW_AT_decl_file ("/home/czhengsz/test/103.c")
DW_AT_decl_line (1)
DW_AT_location (DW_OP_addrx 0x0, DW_OP_deref_size 0x1, DW_OP_constu 0x5a, DW_OP_mul, DW_OP_lit10, DW_OP_plus, DW_OP_stack_value)
```
The location for `data2` is not right, the content at address index addrx 0x0 is 0, so it always returns 10 for `p data2` in GDB.
```
(gdb) b main
Breakpoint 1 at 0x10958: file 103.c, line 18.
(gdb) r
Starting program: a.out
Breakpoint 1, set1 () at 103.c:4
4 data2 = 100;
(gdb) p data2
$1 = 10
(gdb) n
main () at 103.c:19
19 return get();
(gdb) p data2
$2 = 10 ////This seems not right, should be 100 now.
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVU1vqzoT_jXOZlRkTEhgkUValKN3dV7d26MukcED-B5jI2zatL_-ynyEtGl7D0JCjGeeZ77NrZW1RjyQ-J7E2YYPrjH9oWxQvzWo65BGdFMY8XogOzq_NCP0aB13sgSpHQjuOAMSZRBSEt1P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