Skip to content

[Flang] Endless recursion in compilation of derived types that have a triangular reference #65572

@yus3710-fj

Description

@yus3710-fj

This is an issue from Fujitsu testsuite.

Flang-new terminates abnormally when compiling derived types that have a triangular reference.
If the variable of the derived type isn't in a common block, this issue isn't reproduced.

The following are the test program, Flang-new and gfortran compilation result.

! test.f90
module mod
  type ty1
    sequence
    type (ty2),pointer :: aaa1
  end type
  type ty2
    sequence
    type (ty3),pointer :: aaa2
  end type
  type ty3
    sequence
    type (ty1),pointer :: aaa3
  end type
end

! only test compilation, not execution result
use mod
common sss
type (ty1) :: sss
end
$ flang-new -v test.f90
flang-new version 18.0.0 (https://github.com/llvm/llvm-project.git 701e6f7630474b637e0bc45d009bf2ec47f2d3fd)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/install/bin
Found candidate GCC installation: /usr/lib/gcc/aarch64-redhat-linux/8
Selected GCC installation: /usr/lib/gcc/aarch64-redhat-linux/8
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/path/to/install/bin/flang-new" -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +neon -target-feature +v8a -o /tmp/test-b3bbcd.o -x f95-cpp-input test.f90
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /path/to/install/bin/flang-new -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +neon -target-feature +v8a -o /tmp/test-b3bbcd.o -x f95-cpp-input test.f90
  #0 0x0000ffffada65f60 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/path/to/install/bin/../lib/libLLVMSupport.so.18git+0x1a5f60)
  #1 0x0000ffffada63b40 llvm::sys::RunSignalHandlers() (/path/to/install/bin/../lib/libLLVMSupport.so.18git+0x1a3b40)
  #2 0x0000ffffada63cb0 SignalHandler(int) Signals.cpp:0:0
  #3 0x0000ffffaf54066c (linux-vdso.so.1+0x66c)
  #4 0x0000ffffa9a002c8 Fortran::semantics::DeclarationVisitor::CheckCommonBlockDerivedType(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x4f02c8)
  #5 0x0000ffffa9a003cc Fortran::semantics::DeclarationVisitor::CheckCommonBlockDerivedType(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x4f03cc)
  #6 0x0000ffffa9a003cc Fortran::semantics::DeclarationVisitor::CheckCommonBlockDerivedType(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x4f03cc)
  #7 0x0000ffffa9a003cc Fortran::semantics::DeclarationVisitor::CheckCommonBlockDerivedType(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x4f03cc)
  #8 0x0000ffffa9a003cc Fortran::semantics::DeclarationVisitor::CheckCommonBlockDerivedType(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x4f03cc)
  #9 0x0000ffffa9a003cc Fortran::semantics::DeclarationVisitor::CheckCommonBlockDerivedType(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x4f03cc)
 #10 0x0000ffffa9a003cc Fortran::semantics::DeclarationVisitor::CheckCommonBlockDerivedType(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x4f03cc)
 #11 0x0000ffffa9a003cc Fortran::semantics::DeclarationVisitor::CheckCommonBlockDerivedType(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x4f03cc)
 #12 0x0000ffffa9a003cc Fortran::semantics::DeclarationVisitor::CheckCommonBlockDerivedType(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x4f03cc)
 #13 0x0000ffffa9a003cc Fortran::semantics::DeclarationVisitor::CheckCommonBlockDerivedType(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x4f03cc)
 #14 0x0000ffffa9a003cc Fortran::semantics::DeclarationVisitor::CheckCommonBlockDerivedType(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x4f03cc)
 #15 0x0000ffffa9a003cc Fortran::semantics::DeclarationVisitor::CheckCommonBlockDerivedType(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x4f03cc)
 #16 0x0000ffffa9a003cc Fortran::semantics::DeclarationVisitor::CheckCommonBlockDerivedType(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x4f03cc)
 #17 0x0000ffffa9a003cc Fortran::semantics::DeclarationVisitor::CheckCommonBlockDerivedType(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x4f03cc)
 :
#255 0x0000ffffa9a003cc Fortran::semantics::DeclarationVisitor::CheckCommonBlockDerivedType(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/path/to/install/bin/../lib/../lib/libFortranSemantics.so.18git+0x4f03cc)
flang-new: error: unable to execute command: Segmentation fault (core dumped)
flang-new: error: flang frontend command failed due to signal (use -v to see invocation)
flang-new version 18.0.0 (https://github.com/llvm/llvm-project.git 701e6f7630474b637e0bc45d009bf2ec47f2d3fd)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/install/bin
flang-new: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
flang-new: note: diagnostic msg: /tmp/test-7ead1f
flang-new: note: diagnostic msg: /tmp/test-7ead1f.sh
flang-new: note: diagnostic msg: 

********************
$ gfortran -v test.f90
Driving: gfortran -v test.f90 -l gfortran -l m -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-redhat-linux/8/lto-wrapper
Target: aarch64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-gnu-indirect-function --build=aarch64-redhat-linux
Thread model: posix
gcc version 8.4.1 20200928 (Red Hat 8.4.1-1) (GCC) 
 :
$

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions