Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flang] Compilation abnormally terminates when derived type and interface statement with the same name is defined and used in two modules #121718

Open
ohno-fj opened this issue Jan 6, 2025 · 2 comments
Assignees
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] flang:frontend

Comments

@ohno-fj
Copy link

ohno-fj commented Jan 6, 2025

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:

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
$
@ohno-fj ohno-fj added the flang Flang issues not falling into any other category label Jan 6, 2025
@EugeneZelenko EugeneZelenko added flang:frontend crash Prefer [crash-on-valid] or [crash-on-invalid] and removed flang Flang issues not falling into any other category labels Jan 6, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 6, 2025

@llvm/issue-subscribers-flang-frontend

Author: None (ohno-fj)

``` Version of flang : 20.0.0(c5492e3)/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:

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-&gt;has&lt;UseDetails&gt;()) 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&amp;, 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&amp;, Fortran::semantics::Symbol const&amp;) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x5ea5610)
 #<!-- -->8 0x0000000005ea61d4 Fortran::semantics::ModuleVisitor::Post(Fortran::parser::UseStmt const&amp;) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x5ea61d4)
 #<!-- -->9 0x0000000005eba074 Fortran::semantics::ResolveNamesVisitor::Pre(Fortran::parser::SpecificationPart const&amp;) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x5eba074)
#<!-- -->10 0x0000000005eba5c4 std::enable_if&lt;TupleTrait&lt;Fortran::parser::SpecificationPart&gt;, void&gt;::type Fortran::parser::detail::ParseTreeVisitorLookupScope::Walk&lt;Fortran::parser::SpecificationPart, Fortran::semantics::ResolveNamesVisitor&gt;(Fortran::parser::SpecificationPart const&amp;, Fortran::semantics::ResolveNamesVisitor&amp;) resolve-names.cpp:0:0
#<!-- -->11 0x0000000005ec02a8 Fortran::semantics::ResolveNamesVisitor::ResolveSpecificationParts(Fortran::semantics::ProgramTree&amp;) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x5ec02a8)
#<!-- -->12 0x0000000005ec06d4 Fortran::semantics::ResolveNamesVisitor::Pre(Fortran::parser::ProgramUnit const&amp;) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x5ec06d4)
#<!-- -->13 0x0000000005ec0fac Fortran::semantics::ResolveNames(Fortran::semantics::SemanticsContext&amp;, Fortran::parser::Program const&amp;, Fortran::semantics::Scope&amp;) (/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&amp;, Fortran::frontend::FrontendInputFile const&amp;) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241223-c5492e3c65e4/bin/flang+0x57dd30c)
#<!-- -->18 0x00000000057ce3b8 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&amp;) (/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&lt;char const*&gt;, 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
$

@klausler
Copy link
Contributor

klausler commented Jan 7, 2025

The error that I observe from this test is:

fatal internal error: CHECK(localSymbol->has<UseDetails>()) failed at /home/pklausler/llvm-project/flang/lib/Semantics/resolve-names.cpp(3481)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] flang:frontend
Development

No branches or pull requests

4 participants