<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/123534>123534</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang] Compilation abnormally terminates when interface declaration of function in module is inconsistent with definition of function outside the module
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ohno-fj
</td>
</tr>
</table>
<pre>
```
Version of flang : 20.0.0(f5a35a31bfe6cbc16bec0c130f2bb3632dbf1fbf)/AArch64
```
The attached program is incorrect.
`interface` declaration of `function (px6)` in `module` is inconsistent with definition of `function (px6)` outside the `module`.
- The former: `result-name` is defined as a procedure pointer with an `interface-name` of x2.
- The latter: `result-name` is defined as a procedure pointer with an `interface-name` of x2. and it is associated with the function x2.
In the above case, a compilation terminates abnormally.
This should be detected as an error during compilation.
The following are the test program, Flang, Gfortran and ifx compilation/execution result.
sngg520i_2.f90:
```fortran
module mod
interface
function px6() result(r)
interface
function x2(i) result(r)
character(i),pointer::r
end function x2
end interface
procedure (x2),pointer :: r
end function px6
end interface
procedure (x1),pointer :: p
contains
function x1(i) result(r)
character(i),pointer::r
allocate(r)
r='12'
end function x1
end module mod
subroutine s1
use mod
p=>px6()
if (p(2)/='12')print *,3
end subroutine s1
program main
call s1
print *,'pass'
end program main
function x2(i) result(r)
character(i),pointer::r
allocate(r)
r='12'
end function x2
function px6() result(r)
interface
function x2(i) result(r)
character(i),pointer::r
end function x2
end interface
procedure (x2),pointer :: r
r=>x2
end function px6
```
```
$ flang sngg520i_2.f90
fatal internal error: CHECK(symbol.has<DerivedTypeDetails>()) failed at /work/groups/ssoft/compiler/llvm/src/llvm-main/flang/lib/Semantics/mod-file.cpp(1783)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +outline-atomics -target-feature +v8a -target-feature +fp-armv8 -target-feature
+neon -resource-dir /work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/lib/clang/20 -mframe-pointer=non-leaf -o /tmp/sngg520i_2-e3167b.o -x f95-cpp-input sngg520i_2.f90
#0 0x000040003ef271a0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/work/groups/ssoft/compiler/llvm/aarch64/main-latest/lib/libLLVM.so.20.0git+0x59e71a0)
#1 0x000040003ef25228 llvm::sys::RunSignalHandlers() (/work/groups/ssoft/compiler/llvm/aarch64/main-latest/lib/libLLVM.so.20.0git+0x59e5228)
#2 0x000040003ef25380 SignalHandler(int) Signals.cpp:0:0
#3 0x00004000345607a0 (linux-vdso.so.1+0x7a0)
#4 0x0000400043da6274 raise (/lib64/libc.so.6+0x36274)
#5 0x0000400043d90a2c abort (/lib64/libc.so.6+0x20a2c)
#6 0x0000000006d9de34 (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x6d9de34)
#7 0x0000000005fc41e4 (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5fc41e4)
#8 0x0000000005fc456c Fortran::semantics::SubprogramSymbolCollector::DoSymbol(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5fc456c)
#9 0x0000000005fc4760 Fortran::semantics::SubprogramSymbolCollector::DoParamValue(Fortran::semantics::ParamValue const&) (.part.5305) mod-file.cpp:0:0
#10 0x0000000005fc4630 Fortran::semantics::SubprogramSymbolCollector::DoSymbol(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5fc4630)
#11 0x0000000005fc45dc Fortran::semantics::SubprogramSymbolCollector::DoSymbol(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5fc45dc)
#12 0x0000000005fc4c04 Fortran::semantics::SubprogramSymbolCollector::Collect() (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5fc4c04)
#13 0x0000000005fc537c Fortran::semantics::ModFileWriter::PutSubprogram(Fortran::semantics::Symbol const&) (.part.5310) mod-file.cpp:0:0
#14 0x0000000005fc2d80 Fortran::semantics::ModFileWriter::PutSymbol(llvm::raw_ostream&, Fortran::semantics::Symbol const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5fc2d80)
#15 0x0000000005fcc980 Fortran::semantics::ModFileWriter::PutSymbols(Fortran::semantics::Scope const&, std::set<Fortran::common::Reference<Fortran::semantics::Symbol const>, Fortran::semantics::SymbolAddressCompare, std::allocator<Fortran::common::Reference<Fortran::semantics::Symbol const>>>*) (/work/groups/ssoft/c
ompiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5fcc980)
#16 0x0000000005fcad8c Fortran::semantics::ModFileWriter::Write(Fortran::semantics::Symbol const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5fcad8c)
#17 0x0000000005fcd060 Fortran::semantics::ModFileWriter::WriteAll() (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5fcd060)
#18 0x0000000006013328 Fortran::semantics::Semantics::Perform() (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x6013328)
#19 0x0000000005860680 Fortran::frontend::FrontendAction::runSemanticChecks() (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5860680)
#20 0x000000000594d214 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x594d214)
#21 0x0000000005862954 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5862954)
#22 0x0000000005852e48 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5852e48)
#23 0x00000000058671e4 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x58671e4)
#24 0x000000000584b620 fc1_main(llvm::ArrayRef<char const*>, char const*) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x584b620)
#25 0x000000000584b078 main (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x584b078)
#26 0x0000400043d94384 __libc_start_main (/lib64/libc.so.6+0x24384)
#27 0x0000000005849544 _start (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5849544)
flang-20: error: unable to execute command: Aborted (core dumped)
flang-20: error: flang frontend command failed due to signal (use -v to see invocation)
flang version 20.0.0git (https://github.com/llvm/llvm-project.git f5a35a31bfe6cbc16bec0c130f2bb3632dbf1fbf)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin
Build config: +assertions
flang-20: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
flang-20: note: diagnostic msg: /tmp/sngg520i_2-f292c8
flang-20: note: diagnostic msg: /tmp/sngg520i_2-f292c8.sh
flang-20: note: diagnostic msg:
********************
$
```
```
$ cat /tmp/sngg520i_2-f292c8
#line "./sngg520i_2.f90" 1
module mod
interface
function px6() result(r)
interface
function x2(i) result(r)
character(i),pointer::r
end function x2
end interface
procedure (x2),pointer :: r
end function px6
end interface
procedure(x1),pointer :: p
contains
function x1(i) result(r)
character(i),pointer::r
allocate(r)
r='12'
end function x1
end module mod
subroutine s1
use mod
p=>px6()
if(p(2)/='12')print *,3
end subroutine s1
program main
call s1
print *,'pass'
end program main
function x2(i) result(r)
character(i),pointer::r
allocate(r)
r='12'
end function x2
function px6() result(r)
interface
function x2(i) result(r)
character(i),pointer::r
end function x2
end interface
procedure(x2),pointer :: r
r=>x2
end function px6
$
```
```
$ cat /tmp/sngg520i_2-f292c8.sh
# Crash reproducer for clang version 20.0.0git (https://github.com/llvm/llvm-project.git f5a35a31bfe6cbc16bec0c130f2bb3632dbf1fbf)
# Driver args: "sngg520i_2.f90"
# Original command: "/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu" "-emit-obj" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-target-cpu" "generic" "-target-feature" "+outline-atomics" "-target-feature" "+v8a" "-target-featur
e" "+fp-armv8" "-target-feature" "+neon" "-resource-dir" "/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/lib/clang/20" "-mframe-pointer=non-leaf" "-o" "/tmp/sngg520i_2-e3167b.o" "-x" "f95-cpp-input" "sngg520i_2.f90"
"/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu" "-emit-obj" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-target-cpu" "generic" "-target-feature" "+outline-atomics" "-target-feature" "+v8a" "-target-feature" "+fp-armv8" "-tar
get-feature" "+neon" "-mframe-pointer=non-leaf" "-x" "f95-cpp-input" "sngg520i_2-f292c8"
$
```
```
$ gfortran sngg520i_2.f90
sngg520i_2.f90:23:5:
23 | p=>px6()
| 1
Error: Interface mismatch in procedure pointer assignment at (1): Type mismatch in function result (CHARACTER(0)/REAL(4))
sngg520i_2.f90:38:0:
22 | use mod
| 2
......
38 | function px6() result(r)
|
Warning: Type mismatch in function result (REAL(4)/CHARACTER(0)) between (1) and (2)
$
```
```
$ ifx sngg520i_2.f90
ld: /tmp/ifx1801283341ynlOUg/ifx5iC9BO.o: in function `s1_':
sngg520i_2.f90:(.text+0x65): undefined reference to `mod_mp_px6_.2'
ld: /tmp/ifx1801283341ynlOUg/ifx5iC9BO.o: in function `MAIN__':
sngg520i_2.f90:(.text+0x129): undefined reference to `mod_mp_px6_.2'
$
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsW11v2ziz_jXMDSGDoixZvsiF4sRtcbpvizbv7mVAUZTNrUQKJJUm__6ApGx92HGcJs0eHKyRADZFDmeGzwxH4iOiNd8Ixi5BfAXi6wvSmq1Ul3IrZFD-fZHL4vESJKj7Q9mfTGkuBZQlLCsiNhBEGcRohmYI4LSMSRSTKMxLltCchknOKKJhhEqc51ES4SIvwzIvAV4CvM4yRbfJHKBsOANA2e2WQWIMoVtWwEbJjSI15BpyQaVSjJoZhH4UF4apklAGEgQLRiuiiOn0AwkqW0HdT4DT5iGx0yYIcmGv1bJoKzeukyw014YJA39ys4UFK7ngz8qSrdG8YNBs2Uio1zCA1pRSqpop6yiQIMV0W5lAkHo3t5uJFZBoSKy1lBWtYrCRzjivDXEq763dD5clfMDDuSpizO-di4gCcmOFEa0l5cSwwg-0Pth7aacWQNkn4S6RXN4zSIlmAK8ggVTWDa_8chmmai6IYRqSXEhVk6p6nEGHBa6h3sq2KmDOYMEMo6azQECmlFSwaBUXm6HA_dze_1Ulf9oeRPmVMkybHbCsMmsLZfvlQymVUUR4K8uHoUyA1-yB0dYp7F0785NosdnEGPE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