Issue 131606
Summary [flang] Crash with `no-`HLFIR` when using `iso_c_binding` `c_funloc`
Labels flang
Assignees
Reporter jgonzac
    Building the following reduced fortran code causes a crash (`llvm_unreachable` in debug) when building without HLFIR ([llvm godbolt](https://llvm.godbolt.org/z/G4PexP39a))

```fortran
program app
 use, intrinsic :: iso_c_binding, only : c_funptr
  use, intrinsic :: iso_c_binding, only : c_funloc
  implicit none

contains
  subroutine handler()
  end subroutine

  function signal(func)
 procedure(handler) :: func
    type(c_funptr) :: signal
    signal = c_funloc(func)
  end function signal
end program app
```

Compilation with `-flang-deprecated-no-hlfir` flag
```
$ flang -flang-deprecated-no-hlfir example.f90
error: loc("/app/example.f90":13:5): internal: expected a memory reference type '!fir.boxproc<() -> ()>'
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-20250317/bin/flang -fc1 -triple x86_64-unknown-linux-gnu -S -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -flang-deprecated-no-hlfir -resource-dir /opt/compiler-explorer/clang-llvmflang-trunk-20250317/lib/clang/21 -mframe-pointer=all -o /app/output.s -x f95-cpp-input /app/example.f90
 #0 0x0000000003cb03c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-llvmflang-trunk-20250317/bin/flang+0x3cb03c8)
 #1 0x0000000003cadf84 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x00007b4533042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x0000000004d63092 fir::FirOpBuilder::createBox(mlir::Location, fir::ExtendedValue const&, bool, bool) (/opt/compiler-explorer/clang-llvmflang-trunk-20250317/bin/flang+0x4d63092)
 #4 0x00000000042207c9 (anonymous namespace)::ScalarExprLowering::lowerIntrinsicArgumentAsBox(Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&) ConvertExpr.cpp:0:0
 #5 0x00000000042d720b (anonymous namespace)::ScalarExprLowering::genIntrinsicRef(Fortran::evaluate::ProcedureRef const&, std::optional<mlir::Type>, std::optional<Fortran::evaluate::SpecificIntrinsic const>) ConvertExpr.cpp:0:0
 #6 0x0000000004231703 (anonymous namespace)::ScalarExprLowering::genRawProcedureRef(Fortran::evaluate::ProcedureRef const&, std::optional<mlir::Type>) ConvertExpr.cpp:0:0
 #7 0x0000000004234860 (anonymous namespace)::ScalarExprLowering::genProcedureRef(Fortran::evaluate::ProcedureRef const&, std::optional<mlir::Type>) ConvertExpr.cpp:0:0
 #8 0x00000000042a8b43 fir::ExtendedValue (anonymous namespace)::ScalarExprLowering::gen<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)6>>(Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)6>> const&) ConvertExpr.cpp:0:0
 #9 0x000000000421f6c8 fir::ExtendedValue (anonymous namespace)::ScalarExprLowering::gen<Fortran::evaluate::SomeType>(Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&) ConvertExpr.cpp:0:0
#10 0x0000000004220ef8 Fortran::lower::createSomeExtendedAddress(mlir::Location, Fortran::lower::AbstractConverter&, Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&, Fortran::lower::SymMap&, Fortran::lower::StatementContext&) (/opt/compiler-explorer/clang-llvmflang-trunk-20250317/bin/flang+0x4220ef8)
#11 0x00000000040f68cd (anonymous namespace)::FirConverter::genExprAddr(Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&, Fortran::lower::StatementContext&, mlir::Location*) Bridge.cpp:0:0
#12 0x0000000004126ae5 (anonymous namespace)::FirConverter::genAssignment(Fortran::evaluate::Assignment const&)::'lambda3'(Fortran::evaluate::Assignment::Intrinsic const&)::operator()(Fortran::evaluate::Assignment::Intrinsic const&) const (.isra.0) Bridge.cpp:0:0
#13 0x0000000004127af3 (anonymous namespace)::FirConverter::genAssignment(Fortran::evaluate::Assignment const&) Bridge.cpp:0:0
#14 0x000000000413109c (anonymous namespace)::FirConverter::genFIR(Fortran::lower::pft::Evaluation&, bool) (.constprop.0) Bridge.cpp:0:0
#15 0x00000000041351ec (anonymous namespace)::FirConverter::lowerFunc(Fortran::lower::pft::FunctionLikeUnit&) Bridge.cpp:0:0
#16 0x000000000413580b (anonymous namespace)::FirConverter::lowerFunc(Fortran::lower::pft::FunctionLikeUnit&) Bridge.cpp:0:0
#17 0x00000000041378bd Fortran::lower::LoweringBridge::lower(Fortran::parser::Program const&, Fortran::semantics::SemanticsContext const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20250317/bin/flang+0x41378bd)
#18 0x0000000003fb4123 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/opt/compiler-explorer/clang-llvmflang-trunk-20250317/bin/flang+0x3fb4123)
#19 0x0000000003d06765 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20250317/bin/flang+0x3d06765)
#20 0x0000000003cf5087 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/opt/compiler-explorer/clang-llvmflang-trunk-20250317/bin/flang+0x3cf5087)
#21 0x0000000003d10553 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/opt/compiler-explorer/clang-llvmflang-trunk-20250317/bin/flang+0x3d10553)
#22 0x000000000209a10e fc1_main(llvm::ArrayRef<char const*>, char const*) (/opt/compiler-explorer/clang-llvmflang-trunk-20250317/bin/flang+0x209a10e)
#23 0x0000000001f648df main (/opt/compiler-explorer/clang-llvmflang-trunk-20250317/bin/flang+0x1f648df)
#24 0x00007b4533029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#25 0x00007b4533029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#26 0x0000000002098a75 _start (/opt/compiler-explorer/clang-llvmflang-trunk-20250317/bin/flang+0x2098a75)
```

Flang version
```
flang version 21.0.0git (https://github.com/llvm/llvm-project.git 4b86a7f3860a3cb0368e308494f65c103c02fa18)
Target: x86_64-unknown-linux-gnu
```

Is there any expectation on applying fixes to no-HLFIR mode?
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to