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

    <tr>
        <th>Summary</th>
        <td>
            DW_AT_decl_file issue with -gdwarf-5 and -fdebug-prefix-map
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    I've noticed a difference in Clang between DWARF 4 and DWARF 5. This only occurs with `-fdebug-prefix-map` as far as I can tell, so it may be a bug in that code path. GCC has a slightly different bug.

The issue is that `DW_AT_decl_file` attributes (sometimes) have the implicit `DW_AT_comp_dir` explicitly prepended. This leads to confusion with the output from tools such as `llvm-dwarfdump` that (very unhelpfully) also prepend the implicit prefix. More significantly, it breaks tools (like libabigail, for example) that expect

source file name = compilation directory + "/" + declaration file name

Beware! `llvm-dwarfdump` prepends `DW_AT_comp_dir`, always `("p")` in the below example (but `grep`ed out).

Anything with `"p/p"` in the displayed path is wrong. For Clang, that's the cases of compiling either `x.c` or `z/x.c` in `/tmp` and stripping off the prefix `"/tm"`.

```
/tmp$ head x.c z/x.c 
==> x.c <==
int x;

==> z/x.c <==
int x;
/tmp$ for f in x z/x; do for g in 4 5; do for c in gcc-11 gcc-12 gcc-13 clang-13 clang-14 clang-15 clang-16; do
  $c -gdwarf-$g -fdebug-prefix-map=/tm= -c $f.c -o $f.o
  echo -n "$f $g $c"; llvm-dwarfdump $f.o | grep DW_AT_decl_file
done; done; done
x 4 gcc-11 DW_AT_decl_file      ("p/x.c")
x 4 gcc-12 DW_AT_decl_file      ("p/x.c")
x 4 gcc-13 DW_AT_decl_file      ("p/x.c")
x 4 clang-13 DW_AT_decl_file    ("p/x.c")
x 4 clang-14 DW_AT_decl_file    ("p/x.c")
x 4 clang-15 DW_AT_decl_file    ("p/x.c")
x 4 clang-16 DW_AT_decl_file    ("p/x.c")
x 5 gcc-11 DW_AT_decl_file      ("p/p/x.c")
x 5 gcc-12 DW_AT_decl_file      ("p/p/x.c")
x 5 gcc-13 DW_AT_decl_file      ("p/p/x.c")
x 5 clang-13 DW_AT_decl_file    ("p/p/x.c")
x 5 clang-14 DW_AT_decl_file    ("p/p/x.c")
x 5 clang-15 DW_AT_decl_file    ("p/p/x.c")
x 5 clang-16 DW_AT_decl_file    ("p/p/x.c")
z/x 4 gcc-11 DW_AT_decl_file    ("p/z/x.c")
z/x 4 gcc-12 DW_AT_decl_file    ("p/z/x.c")
z/x 4 gcc-13 DW_AT_decl_file    ("p/z/x.c")
z/x 4 clang-13 DW_AT_decl_file  ("p/z/x.c")
z/x 4 clang-14 DW_AT_decl_file  ("p/z/x.c")
z/x 4 clang-15 DW_AT_decl_file  ("p/z/x.c")
z/x 4 clang-16 DW_AT_decl_file  ("p/z/x.c")
z/x 5 gcc-11 DW_AT_decl_file    ("p/z/x.c")
z/x 5 gcc-12 DW_AT_decl_file    ("p/z/x.c")
z/x 5 gcc-13 DW_AT_decl_file    ("p/z/x.c")
z/x 5 clang-13 DW_AT_decl_file  ("p/p/z/x.c")
z/x 5 clang-14 DW_AT_decl_file  ("p/p/z/x.c")
z/x 5 clang-15 DW_AT_decl_file  ("p/p/z/x.c")
z/x 5 clang-16 DW_AT_decl_file  ("p/p/z/x.c")
```

FTR

```
$ clang-16 -v
Debian clang version 16.0.6 (11)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/13
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/13
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
```

</pre>
<img width="1px" height="1px"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