llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.71k stars 10.94k forks source link

[Flang] llvm-project/flang/lib/Lower/ConvertCall.cpp:775: hlfir::EntityWithAttributes genStmtFunctionRef(mlir::Location, Fortran::lower::AbstractConverter &, Fortran::lower::SymMap &, Fortran::lower::StatementContext &, const Fortran::evaluate::ProcedureRef &): Assertion `expr && "assumed type used as statement function argument"' failed. #96424

Open k-arrows opened 1 week ago

k-arrows commented 1 week ago

Crash itself is reproducible on Godbolt: https://godbolt.org/z/GW1heG8KM

Reproducer:

subroutine s(x)
  type(*) :: x
  integer :: i
  i(x) = 0
  print *, i(x)
end subroutine

With assertion-enabled flang-new, compiling the reproducer results in the following assertion failure:

flang-new: /path_to_llvm_project/llvm-project/flang/lib/Lower/ConvertCall.cpp:775: hlfir::EntityWithAttributes genStmtFunctionRef(mlir::Location, Fortran::lower::AbstractConverter &, Fortran::lower::SymMap &, Fortran::lower::StatementContext &, const Fortran::evaluate::ProcedureRef &): Assertion `expr && "assumed type used as statement function argument"' failed.

Stack dump:

PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: /opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new -fc1 -triple x86_64-unknown-linux-gnu -S -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -mllvm -x86-asm-syntax=intel -resource-dir /opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/.. -mframe-pointer=all -o /app/output.s -x f95-cpp-input /app/example.f90
 #0 0x00000000034d3ff8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x34d3ff8)
 #1 0x00000000034d197c SignalHandler(int) Signals.cpp:0:0
 #2 0x000070162fc42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x0000000003afb591 hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeType>(Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&) (.part.0) ConvertExprToHLFIR.cpp:0:0
 #4 0x0000000003afb8cb Fortran::lower::convertExprToHLFIR(mlir::Location, Fortran::lower::AbstractConverter&, Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&, Fortran::lower::SymMap&, Fortran::lower::StatementContext&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x3afb8cb)
 #5 0x000000000391ba6c genProcedureRef((anonymous namespace)::CallContext&) ConvertCall.cpp:0:0
 #6 0x000000000391e244 Fortran::lower::convertCallToHLFIR(mlir::Location, Fortran::lower::AbstractConverter&, Fortran::evaluate::ProcedureRef const&, std::optional<mlir::Type>, Fortran::lower::SymMap&, Fortran::lower::StatementContext&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x391e244)
 #7 0x0000000003aeebb0 hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::Type<(Fortran::common::TypeCategory)0, 4>>(Fortran::evaluate::Expr<Fortran::evaluate::Type<(Fortran::common::TypeCategory)0, 4>> const&) ConvertExprToHLFIR.cpp:0:0
 #8 0x0000000003ace4a0 hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)0>>(Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)0>> const&) ConvertExprToHLFIR.cpp:0:0
 #9 0x0000000003afb6dd hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeType>(Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&) (.part.0) ConvertExprToHLFIR.cpp:0:0
#10 0x0000000003afb95d Fortran::lower::convertExprToValue(mlir::Location, Fortran::lower::AbstractConverter&, Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&, Fortran::lower::SymMap&, Fortran::lower::StatementContext&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x3afb95d)
#11 0x000000000387da95 (anonymous namespace)::FirConverter::genExprValue(Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&, Fortran::lower::StatementContext&, mlir::Location*) Bridge.cpp:0:0
#12 0x0000000003b57ae7 genOutputItemList(Fortran::lower::AbstractConverter&, mlir::Value, std::__cxx11::list<Fortran::parser::OutputItem, std::allocator<Fortran::parser::OutputItem>> const&, bool, bool, mlir::Value&, bool) IO.cpp:0:0
#13 0x0000000003b5e2c1 mlir::Value genDataTransferStmt<false, false, Fortran::parser::PrintStmt>(Fortran::lower::AbstractConverter&, Fortran::parser::PrintStmt const&) IO.cpp:0:0
#14 0x00000000038ef0bb (anonymous namespace)::FirConverter::genFIR(Fortran::lower::pft::Evaluation&, bool) (.constprop.0) Bridge.cpp:0:0
#15 0x00000000038f2e6c (anonymous namespace)::FirConverter::lowerFunc(Fortran::lower::pft::FunctionLikeUnit&) Bridge.cpp:0:0
#16 0x00000000038f4c9c Fortran::lower::LoweringBridge::lower(Fortran::parser::Program const&, Fortran::semantics::SemanticsContext const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x38f4c9c)
#17 0x000000000385b3f9 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x385b3f9)
#18 0x000000000352ada5 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x352ada5)
#19 0x000000000351a807 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x351a807)
#20 0x0000000003530ded Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x3530ded)
#21 0x0000000001c3a088 fc1_main(llvm::ArrayRef<char const*>, char const*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x1c3a088)
#22 0x0000000001b22244 main (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x1b22244)
#23 0x000070162fc29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#24 0x000070162fc29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#25 0x0000000001c38fee _start (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x1c38fee)
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 19.0.0git (https://github.com/llvm/llvm-project.git f73ac218a666e2017565f2210b47332ddcf55f00)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin
llvmbot commented 1 week ago

@llvm/issue-subscribers-flang-ir

Author: None (k-arrows)

Crash itself is reproducible on Godbolt: https://godbolt.org/z/GW1heG8KM Reproducer: ```f90 subroutine s(x) type(*) :: x integer :: i i(x) = 0 print *, i(x) end subroutine ``` With assertion-enabled flang-new, compiling the reproducer results in the following assertion failure: ```txt flang-new: /path_to_llvm_project/llvm-project/flang/lib/Lower/ConvertCall.cpp:775: hlfir::EntityWithAttributes genStmtFunctionRef(mlir::Location, Fortran::lower::AbstractConverter &, Fortran::lower::SymMap &, Fortran::lower::StatementContext &, const Fortran::evaluate::ProcedureRef &): Assertion `expr && "assumed type used as statement function argument"' failed. ``` Stack dump: ```console PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: /opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new -fc1 -triple x86_64-unknown-linux-gnu -S -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -mllvm -x86-asm-syntax=intel -resource-dir /opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/.. -mframe-pointer=all -o /app/output.s -x f95-cpp-input /app/example.f90 #0 0x00000000034d3ff8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x34d3ff8) #1 0x00000000034d197c SignalHandler(int) Signals.cpp:0:0 #2 0x000070162fc42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #3 0x0000000003afb591 hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeType>(Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&) (.part.0) ConvertExprToHLFIR.cpp:0:0 #4 0x0000000003afb8cb Fortran::lower::convertExprToHLFIR(mlir::Location, Fortran::lower::AbstractConverter&, Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&, Fortran::lower::SymMap&, Fortran::lower::StatementContext&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x3afb8cb) #5 0x000000000391ba6c genProcedureRef((anonymous namespace)::CallContext&) ConvertCall.cpp:0:0 #6 0x000000000391e244 Fortran::lower::convertCallToHLFIR(mlir::Location, Fortran::lower::AbstractConverter&, Fortran::evaluate::ProcedureRef const&, std::optional<mlir::Type>, Fortran::lower::SymMap&, Fortran::lower::StatementContext&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x391e244) #7 0x0000000003aeebb0 hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::Type<(Fortran::common::TypeCategory)0, 4>>(Fortran::evaluate::Expr<Fortran::evaluate::Type<(Fortran::common::TypeCategory)0, 4>> const&) ConvertExprToHLFIR.cpp:0:0 #8 0x0000000003ace4a0 hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)0>>(Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)0>> const&) ConvertExprToHLFIR.cpp:0:0 #9 0x0000000003afb6dd hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeType>(Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&) (.part.0) ConvertExprToHLFIR.cpp:0:0 #10 0x0000000003afb95d Fortran::lower::convertExprToValue(mlir::Location, Fortran::lower::AbstractConverter&, Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&, Fortran::lower::SymMap&, Fortran::lower::StatementContext&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x3afb95d) #11 0x000000000387da95 (anonymous namespace)::FirConverter::genExprValue(Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&, Fortran::lower::StatementContext&, mlir::Location*) Bridge.cpp:0:0 #12 0x0000000003b57ae7 genOutputItemList(Fortran::lower::AbstractConverter&, mlir::Value, std::__cxx11::list<Fortran::parser::OutputItem, std::allocator<Fortran::parser::OutputItem>> const&, bool, bool, mlir::Value&, bool) IO.cpp:0:0 #13 0x0000000003b5e2c1 mlir::Value genDataTransferStmt<false, false, Fortran::parser::PrintStmt>(Fortran::lower::AbstractConverter&, Fortran::parser::PrintStmt const&) IO.cpp:0:0 #14 0x00000000038ef0bb (anonymous namespace)::FirConverter::genFIR(Fortran::lower::pft::Evaluation&, bool) (.constprop.0) Bridge.cpp:0:0 #15 0x00000000038f2e6c (anonymous namespace)::FirConverter::lowerFunc(Fortran::lower::pft::FunctionLikeUnit&) Bridge.cpp:0:0 #16 0x00000000038f4c9c Fortran::lower::LoweringBridge::lower(Fortran::parser::Program const&, Fortran::semantics::SemanticsContext const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x38f4c9c) #17 0x000000000385b3f9 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x385b3f9) #18 0x000000000352ada5 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x352ada5) #19 0x000000000351a807 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x351a807) #20 0x0000000003530ded Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x3530ded) #21 0x0000000001c3a088 fc1_main(llvm::ArrayRef<char const*>, char const*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x1c3a088) #22 0x0000000001b22244 main (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x1b22244) #23 0x000070162fc29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #24 0x000070162fc29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #25 0x0000000001c38fee _start (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x1c38fee) 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 19.0.0git (https://github.com/llvm/llvm-project.git f73ac218a666e2017565f2210b47332ddcf55f00) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin ```
llvmbot commented 1 week ago

@llvm/issue-subscribers-bug

Author: None (k-arrows)

Crash itself is reproducible on Godbolt: https://godbolt.org/z/GW1heG8KM Reproducer: ```f90 subroutine s(x) type(*) :: x integer :: i i(x) = 0 print *, i(x) end subroutine ``` With assertion-enabled flang-new, compiling the reproducer results in the following assertion failure: ```txt flang-new: /path_to_llvm_project/llvm-project/flang/lib/Lower/ConvertCall.cpp:775: hlfir::EntityWithAttributes genStmtFunctionRef(mlir::Location, Fortran::lower::AbstractConverter &, Fortran::lower::SymMap &, Fortran::lower::StatementContext &, const Fortran::evaluate::ProcedureRef &): Assertion `expr && "assumed type used as statement function argument"' failed. ``` Stack dump: ```console PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: /opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new -fc1 -triple x86_64-unknown-linux-gnu -S -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -mllvm -x86-asm-syntax=intel -resource-dir /opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/.. -mframe-pointer=all -o /app/output.s -x f95-cpp-input /app/example.f90 #0 0x00000000034d3ff8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x34d3ff8) #1 0x00000000034d197c SignalHandler(int) Signals.cpp:0:0 #2 0x000070162fc42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #3 0x0000000003afb591 hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeType>(Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&) (.part.0) ConvertExprToHLFIR.cpp:0:0 #4 0x0000000003afb8cb Fortran::lower::convertExprToHLFIR(mlir::Location, Fortran::lower::AbstractConverter&, Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&, Fortran::lower::SymMap&, Fortran::lower::StatementContext&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x3afb8cb) #5 0x000000000391ba6c genProcedureRef((anonymous namespace)::CallContext&) ConvertCall.cpp:0:0 #6 0x000000000391e244 Fortran::lower::convertCallToHLFIR(mlir::Location, Fortran::lower::AbstractConverter&, Fortran::evaluate::ProcedureRef const&, std::optional<mlir::Type>, Fortran::lower::SymMap&, Fortran::lower::StatementContext&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x391e244) #7 0x0000000003aeebb0 hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::Type<(Fortran::common::TypeCategory)0, 4>>(Fortran::evaluate::Expr<Fortran::evaluate::Type<(Fortran::common::TypeCategory)0, 4>> const&) ConvertExprToHLFIR.cpp:0:0 #8 0x0000000003ace4a0 hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)0>>(Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)0>> const&) ConvertExprToHLFIR.cpp:0:0 #9 0x0000000003afb6dd hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeType>(Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&) (.part.0) ConvertExprToHLFIR.cpp:0:0 #10 0x0000000003afb95d Fortran::lower::convertExprToValue(mlir::Location, Fortran::lower::AbstractConverter&, Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&, Fortran::lower::SymMap&, Fortran::lower::StatementContext&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x3afb95d) #11 0x000000000387da95 (anonymous namespace)::FirConverter::genExprValue(Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&, Fortran::lower::StatementContext&, mlir::Location*) Bridge.cpp:0:0 #12 0x0000000003b57ae7 genOutputItemList(Fortran::lower::AbstractConverter&, mlir::Value, std::__cxx11::list<Fortran::parser::OutputItem, std::allocator<Fortran::parser::OutputItem>> const&, bool, bool, mlir::Value&, bool) IO.cpp:0:0 #13 0x0000000003b5e2c1 mlir::Value genDataTransferStmt<false, false, Fortran::parser::PrintStmt>(Fortran::lower::AbstractConverter&, Fortran::parser::PrintStmt const&) IO.cpp:0:0 #14 0x00000000038ef0bb (anonymous namespace)::FirConverter::genFIR(Fortran::lower::pft::Evaluation&, bool) (.constprop.0) Bridge.cpp:0:0 #15 0x00000000038f2e6c (anonymous namespace)::FirConverter::lowerFunc(Fortran::lower::pft::FunctionLikeUnit&) Bridge.cpp:0:0 #16 0x00000000038f4c9c Fortran::lower::LoweringBridge::lower(Fortran::parser::Program const&, Fortran::semantics::SemanticsContext const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x38f4c9c) #17 0x000000000385b3f9 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x385b3f9) #18 0x000000000352ada5 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x352ada5) #19 0x000000000351a807 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x351a807) #20 0x0000000003530ded Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x3530ded) #21 0x0000000001c3a088 fc1_main(llvm::ArrayRef<char const*>, char const*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x1c3a088) #22 0x0000000001b22244 main (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x1b22244) #23 0x000070162fc29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #24 0x000070162fc29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #25 0x0000000001c38fee _start (/opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin/flang-new+0x1c38fee) 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 19.0.0git (https://github.com/llvm/llvm-project.git f73ac218a666e2017565f2210b47332ddcf55f00) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /opt/compiler-explorer/clang-llvmflang-trunk-20240623/bin ```