llvm-project
fe84f6e3 - [flang] Use the ultimate symbol location for semantics-created callee names (#235808)

Commit
8 days ago
[flang] Use the ultimate symbol location for semantics-created callee names (#235808) When a module procedure is only reachable through a use-associated generic, semantics (`ExpressionAnalyzer::AccessSpecific`) adds a renaming USE symbol (e.g. `m$m$nxt`) to the calling scope. This happens both for a USE with an ONLY list that names the generic but not the specific (e.g. `use m, only: get` where `get` resolves to the specific `nxt`), and for a PRIVATE specific behind a PUBLIC generic accessed with a plain `use`. The symbol's name is a saved temporary string with no source provenance, so `getProcedureDesignatorLoc` produced an unknown location for the callee's `func.func` declaration. Any OpenACC `acc.routine` op attached to that function inherits the same unknown location, which breaks consumers that expect a valid location (e.g. optimization remarks). When the designator symbol's name does not map to a source location, fall back to the location of the ultimate symbol, which points into the module file. With the module in a separate file, the declaration now gets e.g. `loc("m.mod":10:10)`, matching what a plain `use m` of a PUBLIC specific already produced. The issue only shows up when the module is in a separate file: when the specific procedure is defined in the same translation unit, the bridge declares it with its definition location before any calls are lowered. Testing: new `flang/test/Lower/generic-specific-callee-loc.f90` (passes with the patch, fails without it); `flang/test/Lower` passes. Assisted-by: AI
Author
Parents
Loading