[flang][debug] use only of procedure introduces MLIR symbols in fir.use_stmt that may not be declared in mlir module
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Reproducer:
In file1.f90
```fortran
module m1
contains
subroutine bar
end subroutine
end module
```
in file2.f90
```fortran
subroutine foo
use m1, only : bar
end subroutine
```
Compile with:
```
flang -c -g file1.f90
flang -fc1 -debug-info-kind=standalone file2.f90 -emit-fir -o -
```
Output is:
```mlir
module attributes {
func.func @_QPfoo() {
%0 = fir.dummy_scope : !fir.dscope
fir.use_stmt "m1" only_symbols[[@_QMm1Pbar]]
return
}
}
```
You can see that the symbol `@_QMm1Pbar` appears in the fir.use_stmt as an MLIR symbol while it is not declared in the module.
This came out as an issue in an OpenACC pass we are working on that is looking at the usages of symbols inside acc routine and could not understand anything about this MLIR symbol without an operation defined inside the MLIR module.
I think either the fir.use_stmt should not contain procedure names (I do not think they matter for debug info/only fir.globals are dealt with in add-debug-info), or a declaration of the func.func should be triggered when it is emitted in a fir.use_stmt.
@abidh, do you see any use case for having procedure inside fir.use_stmt currentlty? This would help chosing one solution or the other.
Contributor guide
Research direction
Reproduce the issue with file1.f90 and file2.f90 using the two flang commands in the report, then inspect the emitted FIR around fir.use_stmt and the OpenACC symbol-usage behavior described. Determine whether procedure names should be omitted or declared when emitted; done means the FIR no longer exposes an undeclared MLIR symbol, with the chosen behavior covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fortran
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100