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

    <tr>
        <th>Summary</th>
        <td>
            [DWARF5][clang] Clang does not produce some DW_TAG_call_site_parameter entries
        </td>
    </tr>

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

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

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

<pre>
    Environment:
Debian clang version 18.1.6 (++20240518023138+1118c2e05e67-1~exp1~20240518143226.133)
Target: x86_64-pc-linux-gnu
Thread model: posix

I have found clang to sometimes skip or change order of produced `DW_TAG_call_site_parameter`s while correctly generating all `DW_TAG_formal_parameter`s.

It does not comply with [DWARF5 standard](https://dwarfstd.org/doc/DWARF5.pdf) (page 91 lines 6-7):
>  Call site parameter entries occur in the same order as the corresponding parameters in the source.

\
Minimum example of the described behaviour:
```c
#include <stdio.h>

__attribute__((noinline)) void test(int a1, const char *str, int a3) {
    printf("%d %s %d\n", a1, str, a3);
}

int main(void) {
    const char *str = "test string";
 test(1,str,3);

    return 0;
}
```
```console
$ clang -g3 -O1 example.c
```
Output of `llvm-dwarfdump ./a.out`:
```

0x0000005b:   DW_TAG_subprogram
 DW_AT_low_pc    (0x0000000000001140)
                DW_AT_high_pc (0x0000000000001155)
                DW_AT_frame_base        (DW_OP_reg7 RSP)
                DW_AT_call_all_calls    (true)
 DW_AT_name      ("test")
                DW_AT_decl_file ("/app/clang.c")
                DW_AT_decl_line (3)
 DW_AT_prototyped        (true)
                DW_AT_external (true)

0x00000066:     DW_TAG_formal_parameter
 DW_AT_location        (indexed (0x0) loclist = 0x0000001c: 
 [0x0000000000001140, 0x000000000000114e): DW_OP_reg5 RDI
 [0x000000000000114e, 0x0000000000001155): DW_OP_reg4 RSI)
 DW_AT_name    ("a1")
                  DW_AT_decl_file ("/app/clang.c")
                  DW_AT_decl_line       (3)
 DW_AT_type    (0x000000ae "int")

0x0000006f: DW_TAG_formal_parameter
                  DW_AT_location        (indexed (0x1) loclist = 0x00000027: 
                     [0x0000000000001140, 0x0000000000001147): DW_OP_reg4 RSI
 [0x0000000000001147, 0x0000000000001155): DW_OP_reg1 RDX)
 DW_AT_name    ("str")
                  DW_AT_decl_file ("/app/clang.c")
                  DW_AT_decl_line       (3)
 DW_AT_type    (0x000000b7 "const char *")

0x00000078: DW_TAG_formal_parameter
                  DW_AT_location        (indexed (0x2) loclist = 0x00000032: 
                     [0x0000000000001140, 0x0000000000001145): DW_OP_reg1 RDX
 [0x0000000000001145, 0x0000000000001155): DW_OP_reg2 RCX)
 DW_AT_name    ("a3")
                  DW_AT_decl_file ("/app/clang.c")
                  DW_AT_decl_line       (3)
 DW_AT_type    (0x000000ae "int")

...

0x000000d9: DW_TAG_call_site
                  DW_AT_call_origin     (0x0000005b "test")
                  DW_AT_call_return_pc (0x0000000000001177)

0x000000df:       DW_TAG_call_site_parameter
 DW_AT_location      (DW_OP_reg1 RDX)
 DW_AT_call_value    (DW_OP_lit3)

0x000000e4: DW_TAG_call_site_parameter
                    DW_AT_location (DW_OP_reg5 RDI)
                    DW_AT_call_value (DW_OP_lit1)

0x000000e9:       NULL
```

Notice that there is no DIE corresponding to `str` and that the parameters are passed in the wrong (in this case reversed) order. 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWMtu6zgS_Rp6U7AgUU8vvEjseBCgp28jfQeZnUCJZYkzEimQlONs-tsHlCzHjh_Joge4QuLYNKvqkOewWBVmjKgk4pLEjyRez1hva6WXpsOdxN2sUPx9-SR3QivZorQkfCD-mvgPaywEk1A2TFawQ22EkhBkXuAlQGhG6COhj9SnkR8HmU_DIHRjQRBkJUU_xiSdB3_hvgv-miYFUUhp4gVhSOhiDPKT6QpdTNhnSZ5E866cN0L2-3kl-8OUWiPj0CqOjZvYKSP241fj6zPUbIewVb3kB7hWgVEtWtGiAfNf0YHS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