<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/102294>102294</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang] clang generates incompatible types on DWARF stack
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          IOVOVHS
      </td>
    </tr>
</table>

<pre>
    When I use gdb to print the variables of a program compiled by clang, gdb displays "incompitable types on dwarf stack". I was going to submit this to gdb, but someone has already submitted the same issue to gdb. This is the gdb [issue](https://sourceware.org/bugzilla/show_bug.cgi?id=30319). gdb developer said that the operand type of DW_OP_constu is generic and cannot be used as an operand with the base type, and quoted the official dwarf documentation. It seems that the operand of DW_OP_constu also needs to be converted. In fact, someone has already submitted the same issue https://github.com/llvm/llvm-project/issues/62118, but no one has responded. If this is correct, just ignore this issue. 

This is the problem I encountered:

``` c
(gdb) b 350
Breakpoint 2 at 0x555555555170: file /home/hzw/experiment/csmith_prog/mutated_progs/random_92.c, line 350.
(gdb) c
Continuing.

Breakpoint 2, func_1 () at /home/hzw/experiment/csmith_prog/mutated_progs/random_92.c:350
350     int8_t c_20455 = c_20443 - c_20444;
(gdb) p c_20383
Incompatible types on DWARF stack
(gdb) info addr c_20383
Symbol "c_20383" is multi-location:
  Range 0x555555555157-0x555555555194: a complex DWARF expression:
     0: DW_OP_constu 66
     2: DW_OP_breg1 0 [$rdx]
 4: DW_OP_constu 4294967295
    10: DW_OP_and
    11: DW_OP_convert<DW_ATE_unsigned_32 [0x27]>
    16: DW_OP_convert<DW_ATE_unsigned_8 [0x2c]>
    21: DW_OP_minus
    22: DW_OP_stack_value
```
The value of the variable should be: "66 - (( $rdx & 4294967295) as 32-bit as 8-bit)" ,but gdb think the type of "66" is generic type as the explanation in dwarf document 2.5.1.1 which is incompatible.But lldb prints the variable correctly.
[random_92.zip](https://github.com/user-attachments/files/16521763/random_92.zip)


version:
clang 15.07
lldb 15.07
gdb 13.2

Maybe it is acceptable to ignore this difference between gdb and lldb, but I am not sure.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVk1v2zwS_jX0ZRBBoizbOviQxK-xPiy6aIvmaFDkWGJLkVqSiuP--sVQdiOnPewu3iCwJA7nmeF8PEMRgm4t4pZVT6zaLcQYO-e3h0_fPn37x5dF49Rl-9KhhQOMAaFVDUQHg9c2QuwQXoXXojEYwJ1AwOBd60UP0vWDNqiguYA0wraMPydlpcNgxCUA41zbtC2SPsTLQCAW1Fn4E4Qo5A_GeQYHOIsArdO2JdNhbHpNtnWgz1Y1BN2MEYLr0VmETgQQxqNQl-vuiCo5G0SPoEMY8aqawVfCIahuOhyrntIGVu0Y33QxDoGVj4zvGd8HN3qJZ-Exc75lfN-M7U9tjCBZ587HZmwz2WpW7rVi5a7My6JmvM6mk-MrGjeghyA0-SOmCNKSsCoFgIK4ezl--tdROhviSJ61aNFrCbRHCmtdhAYpGQrooPYXwFnHLiE2IkzxpMiQ5N-ju4XAnU5aamGuYVZOjj3aKKJ2NoNDhIDYh9-9--iYMMGBRVQpCw2CdPYVfUSVwcHCSchI1v-nnNxHu9WxG5tMup7xvTGvt8fD4N13JPh9UguM71e8KDa3OrAObiY9hsFZlZw6TTWjA0jnPU7-fR9DBN1a5_EmDiNmwPIdyx-n33mJDN41Bns4AFrpRhvRoyKXZ_vZKp_-QV4X-CaVaQ0NlFU-LT55FD8GR33EQUTI36rbX7HOWfkIJ20QGN93rkd6_Dwzvse3Ab2mlDG-l6HXsTtS0zG-78coIqr0SUGhvLn-WPNM0lGNtkjms49OXb18djZqO2rbZvPTzP0kmNNo5bEAxjekK-Lf5WH5-Cs06aXWNm6OEeSR58uqAlbupvdlCQ_XtyUrnz6eZkiyclNOgkPiGBH1HcfsXh4_768c80Ff25MDoZS_x_ly6RtniLVuy5xTUfSjifrBOJk66FclAHwWtsW7rFb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