<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/121718>121718</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang] Compilation abnormally terminates when derived type and interface statement with the same name is defined and used in two modules
</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(c5492e3c65e40cdcab9771b692f9ad437c65aa04)/AArch64
```
The attached program has two modules with the same name (`iand`) below.
- The first module (`m1`) has `type-param-name-list` of `derived type`.
- The second module (`m3`) has `type-param-name-list` in `derived type` and `generic-spec` in `interface` statement.
In this case, a compilation terminates abnormally.
The program uses only the definition of module (`m1`).
I suspect that the existence of unused module (`m3`) definitions should not affect the behavior.
The following actions for the program result in successful compilation:
- Module (`m3`) is deleted. or,
- Rename `type-param-name-list` in `derived type` and `generic-spec` in `interface` statement in module (`m3`) to something other than iand.
The following are the test program, Flang, Gfortran and ifx compilation/execution result.
snggz898_21.f90:
```fortran
module m1
type iand
integer:: x1=1
integer:: x2=2
end type iand
contains
subroutine foo
write(6,*) "iand(2,3) = ", iand(2,3)
end subroutine foo
end module m1
module m3
interface iand
integer function zzz(x1,x2) result(r)
character:: x1
integer:: x2
end function zzz
end interface iand
type iand
integer:: x1=1
character:: x2='2'
end type iand
end module m3
program main
use m1
use m3
call foo
print *,'pass'
end program main
integer function zzz(x1,x2) result(r)
character:: x1
integer:: x2
read(x1,*) k
r=k+x2
end function zzz
```
```
$ flang snggz898_21.f90
fatal internal error: CHECK(localSymbol->has<UseDetails>()) failed at /work/groups/ssoft/compiler/llvm/src/llvm-main/flang/lib/Semantics/resolve-names.cpp(3481)
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-20241223-c5492e3c65e4/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-20241223-c5492e3c65e4/lib/clang/20 -mframe-pointer=non-leaf -o /tmp/snggz898_21-f89bf6.o -x f95-cpp-input snggz898_21.f90
#0 0x000040000de135d0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/work/groups/ssoft/compiler/llvm/aarch64/main-latest/lib/libLLVM.so.20.0git+0x5a035d0)
#1 0x000040000de11658 llvm::sys::RunSignalHandlers() (/work/groups/ssoft/compiler/llvm/aarch64/main-latest/lib/libLLVM.so.20.0git+0x5a01658)
#2 0x000040000de117b0 SignalHandler(int) Signals.cpp:0:0
#3 0x00004000034707a0 (linux-vdso.so.1+0x7a0)
#4 0x0000400012c76274 raise (/lib64/libc.so.6+0x36274)
#5 0x0000400012c60a2c abort (/lib64/libc.so.6+0x20a2c)
#6 0x0000000006ae94d4 (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x6ae94d4)
#7 0x0000000005ea5610 Fortran::semantics::ModuleVisitor::DoAddUse(Fortran::parser::CharBlock, Fortran::parser::CharBlock, Fortran::semantics::Symbol&, Fortran::semantics::Symbol const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x5ea5610)
#8 0x0000000005ea61d4 Fortran::semantics::ModuleVisitor::Post(Fortran::parser::UseStmt const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x5ea61d4)
#9 0x0000000005eba074 Fortran::semantics::ResolveNamesVisitor::Pre(Fortran::parser::SpecificationPart const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x5eba074)
#10 0x0000000005eba5c4 std::enable_if<TupleTrait<Fortran::parser::SpecificationPart>, void>::type Fortran::parser::detail::ParseTreeVisitorLookupScope::Walk<Fortran::parser::SpecificationPart, Fortran::semantics::ResolveNamesVisitor>(Fortran::parser::SpecificationPart const&, Fortran::semantics::ResolveNamesVisitor&) resolve-names.cpp:0:0
#11 0x0000000005ec02a8 Fortran::semantics::ResolveNamesVisitor::ResolveSpecificationParts(Fortran::semantics::ProgramTree&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x5ec02a8)
#12 0x0000000005ec06d4 Fortran::semantics::ResolveNamesVisitor::Pre(Fortran::parser::ProgramUnit const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x5ec06d4)
#13 0x0000000005ec0fac Fortran::semantics::ResolveNames(Fortran::semantics::SemanticsContext&, Fortran::parser::Program const&, Fortran::semantics::Scope&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x5ec0fac)
#14 0x0000000005f8532c Fortran::semantics::Semantics::Perform() (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x5f8532c)
#15 0x00000000057dbc78 Fortran::frontend::FrontendAction::runSemanticChecks() (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x57dbc78)
#16 0x00000000058c7064 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x58c7064)
#17 0x00000000057dd30c Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x57dd30c)
#18 0x00000000057ce3b8 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x57ce3b8)
#19 0x00000000057e1adc Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x57e1adc)
#20 0x00000000057c6b90 fc1_main(llvm::ArrayRef<char const*>, char const*) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x57c6b90)
#21 0x00000000057c65e8 main (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x57c65e8)
#22 0x0000400012c64384 __libc_start_main (/lib64/libc.so.6+0x24384)
#23 0x00000000057c4ab4 _start (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x57c4ab4)
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 c5492e3c65e40cdcab9771b692f9ad437c65aa04)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/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/snggz898_21-4a6a94
flang-20: note: diagnostic msg: /tmp/snggz898_21-4a6a94.sh
flang-20: note: diagnostic msg:
********************
$
```
```
$ cat /tmp/snggz898_21-4a6a94
#line "./snggz898_21.f90" 1
module m1
type iand
integer:: x1=1
integer:: x2=2
end type iand
contains
subroutine foo
write(6,*) "iand(2,3) = ", iand(2,3)
end subroutine foo
end module m1
module m3
interface iand
integer function zzz(x1,x2) result(r)
character:: x1
integer:: x2
end function zzz
end interface iand
type iand
integer:: x1=1
character:: x2='2'
end type iand
end module m3
program main
use m1
use m3
call foo
print *,'pass'
end program main
integer function zzz(x1,x2) result(r)
character:: x1
integer:: x2
read(x1,*) k
r=k+x2
end function zzz
$
```
```
$ cat /tmp/snggz898_21-4a6a94.sh
# Crash reproducer for clang version 20.0.0git (https://github.com/llvm/llvm-project.git c5492e3c65e40cdcab9771b692f9ad437c65aa04)
# Driver args: "snggz898_21.f90"
# Original command: "/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/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-20241223-c5492e3c65e4/lib/clang/20" "-mframe-pointer=non-leaf" "-o" "/tmp/snggz898_21-f89bf6.o" "-x" "f95-cpp-input" "snggz898_21.f90"
"/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/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" "-mframe-pointer=non-leaf" "-x" "f95-cpp-input" "snggz898_21-4a6a94"
$
```
```
$ gfortran snggz898_21.f90; ./a.out
iand(2,3) = 2 3
pass
$
```
```
$ ifx snggz898_21.f90; ./a.out
iand(2,3) = 2 3
pass
$
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWk1v2zqz_jXMhpAhUbZsL7JwnPi0uH3fFk16zjKgqJHNE4kUSMpJ--sv-CHLVux8tU1xgWu0gUWOhvM8MyTHHFKt-VoAnKPJBZpcntHWbKQ6lxsho_Lfs1wW389RFod_8eJvUJpLgWWJy4qKNUbpApN4FI9iRGZsMp4TSFk2gXHMCkbz-XSa5NmclHNajNMpyyaUxmNE5oisFgvFNtkYxYv9EVC8uNk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