[flang-commits] [flang] Reland [flang][debug] Emit debug info for named constants- #213974 (PR #215369)
Eugene Epshteyn via flang-commits
flang-commits at lists.llvm.org
Tue Aug 11 05:48:05 PDT 2026
================
@@ -510,8 +521,27 @@ void AddDebugInfoPass::handleGlobalOp(fir::GlobalOp globalOp,
mlir::OpBuilder builder(context);
std::pair result = fir::NameUniquer::deconstruct(globalOp.getSymName());
- if (result.first != fir::NameUniquer::NameKind::VARIABLE)
+ switch (result.first) {
+ case fir::NameUniquer::NameKind::VARIABLE:
+ break;
+ case fir::NameUniquer::NameKind::CONSTANT:
+ // A constant local to a procedure is described while walking that
+ // procedure, where `scope` is its DISubprogramAttr. Reaching here with any
+ // other scope means the procedure is not in the IR, typically because it
+ // was never called and got removed while its constant survived. There is
+ // no procedure to attach the constant to, and describing it at compile
+ // unit scope would wrongly make it visible everywhere.
+ if (!isModuleLevelName(result.second) &&
+ !mlir::isa<mlir::LLVM::DISubprogramAttr>(scope))
+ return;
+ // Don't describe a constant for which we only have a declaration. It could
----------------
eugeneepshteyn wrote:
Please check the following case:
Module:
```
module mdef
implicit none
integer, parameter :: kk = 11
integer, parameter :: tbl(4) = [1,2,3,4]
integer :: mvar = 7
end module mdef
```
This is the regular use of the module, should work fine with the current change:
```
program uall
use mdef
implicit none
print *, kk, tbl(2), mvar
end program uall
```
This is USE/ONLY case. Does it still work?
```
program uonly
use mdef, only: kk, tbl, mvar
! Try variations: use all module declarations with ONLY, then use various subsets.
implicit none
! Only print things that appear in ONLY:
print *, kk, tbl(2), mvar
end program uonly
```
https://github.com/llvm/llvm-project/pull/215369
More information about the flang-commits
mailing list