[flang-commits] [flang] [flang][debug] Emit debug info for procedures from an INCLUDE'd file. (PR #225068)

Abid Qadeer via flang-commits flang-commits at lists.llvm.org
Tue Sep 22 04:09:14 PDT 2026


abidh wrote:

> Thanks @abidh for fixing the location info for procedures from an INCLUDE'd file. One thing I noticed is that the dummy arguments of those procedures still carry incorrect file info, e.g. in the added test, `i` gets:
> 
> ```
> !1 = !DIFile(filename: "main.f90", ...)
> ...
> !4 = distinct !DISubprogram(name: "included_sub", ... file: !5, line: 4, scopeLine: 4, ...)
> !5 = !DIFile(filename: "body.f90", ...)
> ...
> !10 = !DILocalVariable(name: "i", arg: 1, scope: !4, file: !1, line: 5, type: !8)
> ```
> 
> where `i` has `file: !1` and is therefore associated with `main.f90:5` instead of `body.f90:5`; the line number and the `scope: !4` are both correct; only the file is off.
> 
> It would be nice if the dummy arguments could be handled in the same PR.

Thanks for catching this. You're right, and it isn't limited to dummy arguments — locals, module variables and the modules themselves all had the same problem. Only handleFuncOp derived a file from the operation's own location; everything else used the compile unit's file while taking its line from the location, which is why the line and scope looked right and only the file was off.

The PR now also:

moves that lookup into a helper and uses it for local variables and globals, so i in the test is described in body.f90 rather than main.f90;
takes a DIModule's file from the MODULE statement, which it was already using for the line;
add test for module in an include file.

Globals, locals and modules now take the file attribute from their own location, as subprograms already did, and that needs a little test churn. For a compilation without INCLUDE the emitted DWARF is unchanged.

A derived type declared in an INCLUDE'd file still gets the compile unit's file. That comes from the fileAttr threaded into DebugTypeGenerator, and fixing it means deriving the file from the fir.type_info location and sharing the helper across the two files. This looks like a bigger change which I will do separately as a follow up.

https://github.com/llvm/llvm-project/pull/225068


More information about the flang-commits mailing list