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 error when a constructor of derived type with extends (derived type with private attribute is specified in extends) #120922

Open
ohno-fj opened this issue Dec 22, 2024 · 0 comments
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] flang:fir-hlfir

Comments

@ohno-fj
Copy link

ohno-fj commented Dec 22, 2024

Version of flang : 20.0.0(8d550aa0f027eb2cf32850f3905dc1db22317587)/AArch64

When a constructor of derived type with extends (derived type with private attribute is specified in extends) is accessed, a compilation error occurs.

The following are the test program, Flang, Gfortran and ifx compilation/execution result.

snfm0301_027_2.f90:

program main
  call test02()
  print *,"pass"
end program main

module mod2
  type,private:: tt
     integer :: ip = 1
  end type tt
  type,extends(tt):: ty1
     integer :: i1 = 1
     type(tt) :: i1p = tt(2)
     integer,allocatable :: i1a(:)
  end type ty1
  type(ty1) :: str
end module mod2

subroutine test02()
  use mod2
  integer,allocatable :: ia(:)
  allocate(ia(10))
  ia=2
  str=ty1(i1a=ia)
  if (str%i1.ne.1) print *,'ng'
end subroutine test02
$ flang snfm0301_027_2.f90
flang: /work/groups/ssoft/compiler/llvm/src/llvm-main/flang/lib/Lower/ConvertExprToHLFIR.cpp:1715: hlfir::EntityWithAttributes {anonymous}::HlfirBuilder::gen(const Fortran::evaluate::StructureConstructor&): Assertion `parentCompType && "failed to retrieve parent component type"' failed.
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-20241216-8d550aa0f027/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-20241216-8d550aa0f027/lib/clang/20 -mframe-pointer=non-leaf -o /tmp/snfm0301_027_2-cb3172.o -x f95-cpp-input snfm0301_027_2.f90
 #0 0x0000400017702180 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/work/groups/ssoft/compiler/llvm/aarch64/main-latest/lib/libLLVM.so.20.0git+0x5952180)
 #1 0x0000400017700208 llvm::sys::RunSignalHandlers() (/work/groups/ssoft/compiler/llvm/aarch64/main-latest/lib/libLLVM.so.20.0git+0x5950208)
 #2 0x0000400017700360 SignalHandler(int) Signals.cpp:0:0
 #3 0x000040000ce507a0 (linux-vdso.so.1+0x7a0)
 #4 0x000040001c516274 raise (/lib64/libc.so.6+0x36274)
 #5 0x000040001c500a2c abort (/lib64/libc.so.6+0x20a2c)
 #6 0x000040001c50fba0 __assert_fail_base (/lib64/libc.so.6+0x2fba0)
 #7 0x000040001c50fc18 __assert_perror_fail (/lib64/libc.so.6+0x2fc18)
 #8 0x000000000546359c (anonymous namespace)::HlfirBuilder::gen(Fortran::evaluate::StructureConstructor const&) ConvertExprToHLFIR.cpp:0:0
 #9 0x0000000005463618 std::__detail::__variant::__gen_vtable_impl<std::__detail::__variant::_Multi_array<hlfir::EntityWithAttributes (*)(hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>(Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>> const&)::'lambda'(Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5> const&)&&, std::variant<Fortran::evaluate::Constant<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>, Fortran::evaluate::ArrayConstructor<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>, Fortran::evaluate::StructureConstructor, Fortran::evaluate::Designator<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>, Fortran::evaluate::FunctionRef<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>, Fortran::evaluate::Parentheses<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>> const&)>, std::tuple<std::variant<Fortran::evaluate::Constant<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>, Fortran::evaluate::ArrayConstructor<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>, Fortran::evaluate::StructureConstructor, Fortran::evaluate::Designator<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>, Fortran::evaluate::FunctionRef<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>, Fortran::evaluate::Parentheses<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>> const&>, std::integer_sequence<unsigned long, 2ul>>::__visit_invoke(hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>(Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>> const&)::'lambda'(Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5> const&)&&, std::variant<Fortran::evaluate::Constant<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>, Fortran::evaluate::ArrayConstructor<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>, Fortran::evaluate::StructureConstructor, Fortran::evaluate::Designator<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>, Fortran::evaluate::FunctionRef<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>, Fortran::evaluate::Parentheses<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>> const&) ConvertExprToHLFIR.cpp:0:0
#10 0x000000000541ff34 hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>(Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>> const&) ConvertExprToHLFIR.cpp:0:0
#11 0x000000000541ff68 std::__detail::__variant::__gen_vtable_impl<std::__detail::__variant::_Multi_array<hlfir::EntityWithAttributes (*)(hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeType>(Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&)::'lambda'(Fortran::evaluate::SomeType const&)&&, std::variant<Fortran::evaluate::value::Integer<128, true, 32, unsigned int, unsigned long, 128>, Fortran::evaluate::NullPointer, Fortran::evaluate::ProcedureDesignator, Fortran::evaluate::ProcedureRef, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)0>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)1>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)2>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)3>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)4>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>> const&)>, std::tuple<std::variant<Fortran::evaluate::value::Integer<128, true, 32, unsigned int, unsigned long, 128>, Fortran::evaluate::NullPointer, Fortran::evaluate::ProcedureDesignator, Fortran::evaluate::ProcedureRef, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)0>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)1>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)2>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)3>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)4>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>> const&>, std::integer_sequence<unsigned long, 9ul>>::__visit_invoke(hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeType>(Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&)::'lambda'(Fortran::evaluate::SomeType const&)&&, std::variant<Fortran::evaluate::value::Integer<128, true, 32, unsigned int, unsigned long, 128>, Fortran::evaluate::NullPointer, Fortran::evaluate::ProcedureDesignator, Fortran::evaluate::ProcedureRef, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)0>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)1>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)2>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)3>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)4>>, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>> const&) ConvertExprToHLFIR.cpp:0:0
#12 0x000000000541f868 hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeType>(Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&) ConvertExprToHLFIR.cpp:0:0
#13 0x000000000541f8cc Fortran::lower::convertExprToHLFIR(mlir::Location, Fortran::lower::AbstractConverter&, Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&, Fortran::lower::SymMap&, Fortran::lower::StatementContext&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241216-8d550aa0f027/bin/flang+0x541f8cc)
#14 0x000000000521b77c (anonymous namespace)::FirConverter::genDataAssignment(Fortran::evaluate::Assignment const&, Fortran::evaluate::ProcedureRef const*)::'lambda'(Fortran::lower::StatementContext&)::operator()(Fortran::lower::StatementContext&) const Bridge.cpp:0:0
#15 0x000000000523f4a8 (anonymous namespace)::FirConverter::genDataAssignment(Fortran::evaluate::Assignment const&, Fortran::evaluate::ProcedureRef const*) Bridge.cpp:0:0
#16 0x0000000005231ea4 (anonymous namespace)::FirConverter::genAssignment(Fortran::evaluate::Assignment const&) Bridge.cpp:0:0
#17 0x000000000524c994 (anonymous namespace)::FirConverter::lowerFunc(Fortran::lower::pft::FunctionLikeUnit&) Bridge.cpp:0:0
#18 0x0000000005232de4 Fortran::lower::LoweringBridge::lower(Fortran::parser::Program const&, Fortran::semantics::SemanticsContext const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241216-8d550aa0f027/bin/flang+0x5232de4)
#19 0x00000000051d79e4 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/work/groups/ssoft/compiler/llvm/aarch64/main-20241216-8d550aa0f027/bin/flang+0x51d79e4)
#20 0x00000000050ee2d4 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241216-8d550aa0f027/bin/flang+0x50ee2d4)
#21 0x00000000050df408 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241216-8d550aa0f027/bin/flang+0x50df408)
#22 0x00000000050f2aa4 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241216-8d550aa0f027/bin/flang+0x50f2aa4)
#23 0x00000000050d7be0 fc1_main(llvm::ArrayRef<char const*>, char const*) (/work/groups/ssoft/compiler/llvm/aarch64/main-20241216-8d550aa0f027/bin/flang+0x50d7be0)
#24 0x00000000050d7638 main (/work/groups/ssoft/compiler/llvm/aarch64/main-20241216-8d550aa0f027/bin/flang+0x50d7638)
#25 0x000040001c504384 __libc_start_main (/lib64/libc.so.6+0x24384)
#26 0x00000000050d5b04 _start (/work/groups/ssoft/compiler/llvm/aarch64/main-20241216-8d550aa0f027/bin/flang+0x50d5b04)
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 8d550aa0f027eb2cf32850f3905dc1db22317587)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /work/groups/ssoft/compiler/llvm/aarch64/main-20241216-8d550aa0f027/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/snfm0301_027_2-00d2ab
flang-20: note: diagnostic msg: /tmp/snfm0301_027_2-00d2ab.sh
flang-20: note: diagnostic msg:

********************
$
$ cat /tmp/snfm0301_027_2-00d2ab
#line "./snfm0301_027_2.f90" 1
      program main
      call test02()
      print *,"pass"
      end program main

      module mod2
      type,private:: tt
      integer :: ip = 1
      end type tt
      type,extends(tt):: ty1
      integer :: i1 = 1
      type(tt) :: i1p = tt(2)
      integer,allocatable :: i1a(:)
      end type ty1
      type(ty1) :: str
      end module mod2

      subroutine test02()
      use mod2
      integer,allocatable :: ia(:)
      allocate(ia(10))
      ia=2
      str=ty1(i1a=ia)
      if(str%i1.ne.1) print *,'ng'
      end subroutine test02
$
$ cat /tmp/snfm0301_027_2-00d2ab.sh
# Crash reproducer for clang version 20.0.0git (https://github.com/llvm/llvm-project.git 8d550aa0f027eb2cf32850f3905dc1db22317587)
# Driver args: "snfm0301_027_2.f90"
# Original command:  "/work/groups/ssoft/compiler/llvm/aarch64/main-20241216-8d550aa0f027/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-20241216-8d550aa0f027/lib/clang/20" "-mframe-pointer=non-leaf" "-o" "/tmp/snfm0301_027_2-cb3172.o" "-x" "f95-cpp-input" "snfm0301_027_2.f90"
 "/work/groups/ssoft/compiler/llvm/aarch64/main-20241216-8d550aa0f027/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" "snfm0301_027_2-00d2ab"
$
$ gfortran snfm0301_027_2.f90; ./a.out
 pass
$
$ ifx snfm0301_027_2.f90; ./a.out
 pass
$
@ohno-fj ohno-fj added the flang Flang issues not falling into any other category label Dec 22, 2024
@EugeneZelenko EugeneZelenko added crash Prefer [crash-on-valid] or [crash-on-invalid] flang:fir-hlfir and removed flang Flang issues not falling into any other category labels Dec 23, 2024
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:fir-hlfir
Projects
Development

No branches or pull requests

2 participants