[flang-commits] [flang] [flang] Safer hermetic module file reading (PR #121002)
via flang-commits
flang-commits at lists.llvm.org
Mon Jan 6 05:39:20 PST 2025
jeanPerier wrote:
The patch removed the ambiguous error about the module, but more advanced scenarios where subroutine/variable are referred are still causing semantic errors.
Example:
```
! my_mpi.f90
module my_mpi
! version 1.0
implicit none
integer :: my_mpi_var = 1
contains
subroutine some_mpi_subroutine
print *, my_mpi_var
end subroutine
end module
```
```
! my_lib.f90
module my_lib
use my_mpi
implicit none
contains
subroutine some_lib_subroutine
print *, my_mpi_var
call some_mpi_subroutine()
end subroutine
end module
```
```
my_mpi_v2.f90
module my_mpi
! version 2.0 that is backward compatible (only adding things).
implicit none
integer :: my_mpi_var = 1
integer :: my_mpi_new_var
contains
subroutine some_mpi_subroutine
print *, my_mpi_var
end subroutine
end module
```
```
! main.f90
main.f90
use my_mpi
use my_lib
implicit none
print *, my_mpi_var
call some_lib_subroutine()
call some_mpi_subroutine()
end
```
build script:
```
FC=flang
# Build library with MY_MPI version 1.
rm -rf my_mpi.o my_mpi.mod
$FC -c my_mpi.f90
rm -rf my_lib.o my_lib.mod
$FC -c -fhermetic-module-files my_lib.f90
# Build application with MY_MPI version 2.
rm -rf my_mpi.o my_mpi.mod
$FC -c my_mpi.f90
$FC -c my_mpi_v2.f90 -o my_mpi.o
$FC main.f90 my_lib.o my_mpi.o
```
With this patch, I am getting the following semantic errors:
```
error: Semantic errors in main.f90
./main.f90:4:12: error: Reference to 'my_mpi_var' is ambiguous
print *, my_mpi_var
^^^^^^^^^^
./main.f90:1:7: 'my_mpi_var' was use-associated from module 'my_mpi'
use my_mpi
^^^^^^
./main.f90:2:7: 'my_mpi_var' was use-associated from module 'my_lib'
use my_lib
^^^^^^
./main.f90:6:8: error: Reference to 'some_mpi_subroutine' is ambiguous
call some_mpi_subroutine()
^^^^^^^^^^^^^^^^^^^
./main.f90:1:7: 'some_mpi_subroutine' was use-associated from module 'my_mpi'
use my_mpi
^^^^^^
./main.f90:2:7: 'some_mpi_subroutine' was use-associated from module 'my_lib'
use my_lib
```
https://github.com/llvm/llvm-project/pull/121002
More information about the flang-commits
mailing list