<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/75206>75206</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Debug location for char parameter emitted with DW_OP_piece 4, causes errors in GDB and Clang
</td>
</tr>
<tr>
<th>Labels</th>
<td>
debuginfo
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dstenb
</td>
</tr>
</table>
<pre>
LLVM commit: ef35da825f38a86e4621c13a2898d561da88991c
When compiling the following program:
```
int a, b;
void c(char d) { a = d & 5; }
void main() {
unsigned long long e = b;
c(e >> 48);
}
```
for i386 using:
```
clang -m32 -O3 -g foo.c
```
GDB 13.1 will emit an error when trying to print `d`:
```
(gdb) b c
Breakpoint 1 at 0x11e1: c. (2 locations)
(gdb) run
Starting program: foo.out
Breakpoint 1.2, c (d=<error reading variable: access outside bounds of object referenced via synthetic pointer>) at reduce1.c:2
2 void c(char d) { a = d & 5; }
```
and LLDB from same LLVM commit crashes:
```
(lldb) b c
Breakpoint 1: 2 locations.
(lldb) run
Process 164454 launched: 'foo.out' (i386)
lldb: /upstream/llvm-project/lldb/source/Expression/DWARFExpression.cpp:2192: static bool lldb_private::DWARFExpression::Evaluate(lldb_private::ExecutionContext *, lldb_private::RegisterContext *, lldb::ModuleSP, const
lldb_private::DataExtractor &, const lldb_private::plugin::dwarf::DWARFUnit *, const lldb::RegisterKind, const lldb_private::Value *, const lldb_private::Value *, lldb_private::Value &, lldb_private::Status *): Assertion `ap_int.g
etBitWidth() >= bit_size' failed.
LLDB diagnostics will be written to /tmp/diagnostics-6d67d3
Please include the directory content when filing a bug report
Aborted (core dumped)
```
The DW_AT_location in question looks like:
```
0x00000096: DW_TAG_formal_parameter
DW_AT_location (indexed (0x1) loclist = 0x0000001e:
[0x00001208, 0x0000120b): DW_OP_breg1 ECX+0, DW_OP_convert (0x00000027) "DW_ATE_unsigned_64", DW_OP_convert (0x0000002b) "DW_ATE_unsigned_8", DW_OP_stack_value, DW_OP_piece 0x4)
DW_AT_abstract_origin (0x00000065 "d")
```
As seen, a 4-byte `DW_OP_piece` has been emitted for the 8-bit type, and applied to a `DW_ATE_unsigned_8` converted value on the stack, which at least looks suspicious.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVt1y6jgSfhpx0xXKlo0xF1xAgLnYMzWn5pyd7B0lS42tjZC8kpyQffqtlgkhP4etoVKuWO7-uvvrP4kQdGsRl2y2ZrPNRAyxc36pQkTbTBqnXpbfvv31O0h3POrIihXgoZgpUfPZoahFXWFZ8VzmheD1olazKleirheLXLJsw7LV-Hzo0BJEr422LcQO4eCMcc_01nvXenFkxepahVXZ-S-9ahtBMH4PDSvW49GT0wok47XshAfF-ALYfA0CWLEBBYxXMGPFGth8c6VwFNoyXp-lxw8Ag000KDDOtuMDE86bOUi26HTLii2UBHH5eLHxwe3xeXAedFFXMARt29uBSiNsC3fHgsPdHwXctXBwbipvoP-2WUNeTHN41sYAHnUEYQG9dx6eifjoXxLrDnpPPLIqU4Rx0w_G61Y1RFMDZ-trj-KxdwSRg4iQnfIcc6oJOQXGaw7GSRG1s4G4-QDjBzse_YjCx_eJTzG6IcK1Q9fmppxyL8mKYsWGFfdjfB6FIqgn4bVoDBKWkBJDADfEoBVC4warArgDuObfKCN4PKBHK1HBkxYQXmzsMGoJyRZ6SjBfUIAe1SAxn0pWrPjoFAf423X3ZdaEVfDt22YNB--OEMQR4arRQHoROgz_N0fG3EgSsXGVlOknrUtOvnuXSMurspyVYMRgZYeKABifn7PD-JwSQJV8yW9CSlK7oQ_RozgyvjPm6XjXe0d8p1cytwtu8BIZ321PvccQtLOM7zYPqz-vTqay74nufMEJN0RBqWmcM0Aw-97rJxEp0axYfdAdD7dPwgwkMsb5XmN7QjkQG_fORjxFYHxFpfVZ8k9sdYjovxAcBX53ajD443uqTGdDPM-JL9wUUWxP0QsZnacCuah8IdybodXnUNSz8IerUP9p9cWRN_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