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

    <tr>
        <th>Summary</th>
        <td>
            DW_AT_NAME is incorrect for Fortran functions compiled by flang
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang:codegen
      </td>
    </tr>

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

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

<pre>
    I compiled this example:
```
integer function my_square(x)
 implicit none
    integer, intent(in) :: x

    my_square = x * x
end function my_square

program hello
  print *, my_square(2)
end program hello
```

Because I wanted to see what lldb would think of it, but it couldn't break on `my_square` when I compiled it with flang, but it could when I used gfortran.

Looking at the DWARF, the DW_AT_NAME for flang includes an `_` on the end.

Gfortran 9.4.0:
```
0x000000bc:   DW_TAG_subprogram
 DW_AT_external  (true)
                DW_AT_name      ("my_square")
 DW_AT_decl_file ("/tmp/test.f90")
 DW_AT_decl_line (1)
                DW_AT_linkage_name ("my_square_")
                DW_AT_type      (0x0000006d "integer(kind=4)")
                DW_AT_low_pc (0x000000000000091c)
                DW_AT_high_pc (0x0000000000000948)
                DW_AT_frame_base (DW_OP_call_frame_cfa)
                DW_AT_GNU_all_call_sites (true)
```

Flang (built from 7d81062352f75cf328d91d4900af52c1842b950e):
```
0x0000002a: DW_TAG_subprogram
                DW_AT_low_pc    (0x0000000000001fa4)
 DW_AT_high_pc   (0x0000000000001fc0)
 DW_AT_frame_base        (DW_OP_reg31 WSP)
 DW_AT_linkage_name      ("my_square_")
                DW_AT_name ("my_square_")
                DW_AT_decl_file ("/tmp/test.f90")
 DW_AT_decl_line (1)
                DW_AT_type (0x0000009c "integer")
                DW_AT_external (true)
```

I think flang is mistakenly using the DW_AT_linkage_name for DW_AT_name.

The workaround is to break on `my_square_`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vt-PozY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