| Issue |
208360
|
| Summary |
[Flang] Compilation error for a generic function in nested submodules
|
| Labels |
flang:frontend
|
| Assignees |
|
| Reporter |
yus3710-fj
|
## Summary
Flang rejects the following program. However, I believe this program is conforming to the Fortran standard.
* 15.5.5.2 Resolving procedure references to names established to be generic
> Otherwise, if the scoping unit has a host scoping unit, the name is established to be generic in that host scoping unit, and there is agreement between the scoping unit and the host scoping unit as to whether the name is a function name or a subroutine name, the name is resolved by applying the rules in this subclause to the host scoping unit as if the reference appeared there.
* 14.2.3 Submodules
> A module or submodule is an ancestor program unit of all of its descendants, which are its submodules and their descendants.
### Reproducer
* test.f90
```fortran
module m1
interface
module function s1()
end
module function s2(d)
end
module subroutine ss()
end
end interface
end
submodule (m1) smod
interface gen
procedure s1,s2
end interface
contains
module procedure s1
s1=1
end
module procedure s2
s2=d
end
end
submodule (m1:smod) smod2
contains
module subroutine ss()
c=gen()
if(c/=1) print *,901
c=gen(2.0)
if(c/=2) print *,902
end
end
use m1
call ss()
print *,'pass'
end
```
* commands
```console
$ flang --version
flang version 23.0.0git (https://github.com/llvm/llvm-project.git ecdd6403fd213f90243a3d354d4db3483b89471f)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/llvm/build/bin
Build config: +assertions
$ flang test.f90 && ./a.out
error: Semantic errors in test.f90
test.f90:28:5: error: No specific function of generic 'gen' matches the actual arguments
c=gen()
^^^^^
test.f90:30:5: error: No specific function of generic 'gen' matches the actual arguments
c=gen(2.0)
^^^^^^^^
```
## Non-problematic Conditions
The issue does not occur under the following conditions:
* Moving the generic interface to either the ancestor module (`m1`) or the innermost submodule (`smod2`).
* Converting functions to subroutines:
```diff
@@ -1,8 +1,8 @@
module m1
interface
- module function s1()
+ module subroutine s1()
end
- module function s2(d)
+ module subroutine s2(d)
end
module subroutine ss()
end
@@ -15,20 +15,16 @@
end interface
contains
module procedure s1
- s1=1
end
module procedure s2
- s2=d
end
end
submodule (m1:smod) smod2
contains
module subroutine ss()
- c=gen()
- if(c/=1) print *,901
- c=gen(2.0)
- if(c/=2) print *,902
+ call gen()
+ call gen(2.0)
end
end
```
## Other Compilers
* GFortran
```console
$ gfortran --version
GNU Fortran (GCC) 15.2.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gfortran test.f90 && ./a.out
pass
```
* Intel Fortran
```console
$ ifx --version
ifx (IFX) 2025.3.2 20260112
Copyright (C) 1985-2026 Intel Corporation. All rights reserved.
$ ifx -O0 test.f90 && ./a.out
ld: /tmp/ifx1919201900Ee6pdS/ifxbe7XlC.o: in function `m1_mp_ss_':
test.f90:(.text+0x79): undefined reference to `m1.smod_mp_s1_'
ld: test.f90:(.text+0x100): undefined reference to `m1.smod_mp_s2_'
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs