<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/120317>120317</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang][debug] Missing renamed module variable
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jieljiel
</td>
</tr>
</table>
<pre>
Example code,
```
module mod1
integer :: a = 1, b = 2
end module
subroutine sub1()
use mod1, foo => a
print *, foo, b
end subroutine
subroutine sub2()
use mod1, only : bar => b
print *, bar
end subroutine
```
With flang, no DW_TAG_variable is generated for `foo` and `bar`.
Proposed solution is to insert metadata nodes of `DIImportedEntity` with `tag:` field to be `DW_TAG_imported_declaration` and `name:` field to be tha variable's name, e.g.
```
!23 = !DIImportedEntity(tag: DW_TAG_imported_declaration, entity: !13, scope: !22, file: !3, line: 5, name: "foo")
!30 = !DIImportedEntity(tag: DW_TAG_imported_declaration, entity: !16, scope: !29, file: !3, line: 10, name: "bar")
```
By looking into the DWARF from gfortran, with or without `only`, the scope could be different though, either belong to the subprogram or the imported module.
```
<1><2f>: Abbrev Number: 4 (DW_TAG_module)
<30> DW_AT_name : (indirect string, offset: 0x10): mod1
...
<1><6f>: Abbrev Number: 6 (DW_TAG_subprogram)
<70> DW_AT_external : 1
<70> DW_AT_name : (indirect string, offset: 0xef): sub1
...
<2><91>: Abbrev Number: 7 (DW_TAG_imported_module)
...
<95> DW_AT_import : <0x2f> [Abbrev Number: 4 (DW_TAG_module)]
<3><99>: Abbrev Number: 2 (DW_TAG_imported_declaration)
...
<9c> DW_AT_name : foo
<a0> DW_AT_import : <0x3b> [Abbrev Number: 1 (DW_TAG_variable)]
...
<1><a6>: Abbrev Number: 8 (DW_TAG_subprogram)
<a7> DW_AT_external : 1
<a7> DW_AT_name : (indirect string, offset: 0xf4): sub2
...
<2><c4>: Abbrev Number: 2 (DW_TAG_imported_declaration)
...
<c7> DW_AT_name : bar
<cb> DW_AT_import : <0x51> [Abbrev Number: 1 (DW_TAG_variable)]
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyslktv4zgSxz8NfSm0QZF6WAcfFDtZ9GEXi0EDOQakRMnsoUSDpDLJtx8UxcRO207Po4MEUqiqf_3qQUrCez1MSm1JcUeK_UrM4WDd9rtWBv9W0nav2_sXMR6NgtZ2irAdoQ0pafqlzWi72SgYbZcR2gDoKahBOSC8IbwBAYTvISNsBzLeMiC0UVMHiyOq0cbP0tk56EmBn2VG2IawOsrNPmmzHfTWogTh9yDiw6PTUwDCmvQ0RknyJ8lrIdiNEHYyr4gOUri3WPIylhTuapizuhDaPOpwgN6IaUCfycL-8elb85-nZ-G0kEaB9jCoSTkRVAe9dUBKimmUFMTU4X8YqKTrRe__zh6tVx14a-ag7YQCwYKevHIBRhVEJ4KAyXbKg-1RYP_163i0Lqjufgo6vKL2H8hFShrEgF0qKfRamQ6lpIpOC6dOnk-dao1wAkOesU1iVFf8w0HAW4aEVR6iHduBWg_rH4vEMsbjWBCWXaCyzUIIn_Gg8GLOG1TJOC751h5VWmEsjoc2bwvRwmDLeANF7M2SChDG4hixZTbQlv5ivPICr_4ML6M_8OFEvPOdlfLuFYy1v-tpwC1oIRwU7B-b3x6gd3aEobcuOBGBYv-ti1c7B-wlzj3qsF10jHzQ2tl02NJO971yagqADsMhZqXDQTmQythpgBTQz_Lo7ODEiPq48laUtN3TJJ-DA-G7jPB7wnesj9cGGimdeob_zaNUDhdyIGyT6pwOjrR7Af05xY26f3xqvj1hrSD9LDXb6KnTTrUBfHB62Y22770K-Jy-YI1rvE2H2Hq9_shV3uQqz7hOyX9gqyIbJDr1EpSbhHmjy1Kkj1Z_PwfVpxzi-XmeA1tyqLNbOVRnObzP8HmRk9aSTl2cSr1Yn2HyHX1ZmkhrUtz9xTYW-4TKE2p9C5VdQ_2w3S5524vCohJu83cb8aH4V7Pi8nZW2RnV6eRLeV0MkyhvZbf5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