<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/145151>145151</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang] crashes when compiling a program that uses elemental function/subroutine
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang:ir,
crash
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
k-arrows
</td>
</tr>
</table>
<pre>
Reproducer:
https://godbolt.org/z/d7zbEcnYb
```f90
module m
integer :: i
contains
elemental function f(c)
character(i) f
character(*), intent(in) :: c
end
elemental subroutine s(c)
character(*), intent(in) :: c
end
end
use m
integer, allocatable :: j(:)
character, dimension(:), pointer :: c1
call s(f(c1(j)))
end
```
Backtrace:
```console
/app/example.f90:4:24: warning: Function result is never defined
elemental function f(c)
^
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-20250621/bin/flang -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-20250621/lib/clang/21 -mframe-pointer=all -o /app/output.s -x f95 /app/example.f90
#0 0x0000000003e736b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-llvmflang-trunk-20250621/bin/flang+0x3e736b8)
#1 0x0000000003e71274 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#2 0x0000795422e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#3 0x000000000431e028 Fortran::lower::PreparedActualArgument::getActual(mlir::Location, fir::FirOpBuilder&) const (/opt/compiler-explorer/clang-llvmflang-trunk-20250621/bin/flang+0x431e028)
#4 0x0000000004320a2f preparePresentUserCallActualArgument(mlir::Location, fir::FirOpBuilder&, Fortran::lower::PreparedActualArgument const&, mlir::Type, Fortran::lower::CallInterface<Fortran::lower::CallerInterface>::PassedEntity const&, (anonymous namespace)::CallContext&) ConvertCall.cpp:0:0
#5 0x0000000004326919 prepareUserCallArguments(llvm::SmallVector<std::optional<Fortran::lower::PreparedActualArgument>, 1u>&, Fortran::lower::CallerInterface&, mlir::FunctionType, (anonymous namespace)::CallContext&, llvm::SmallVector<(anonymous namespace)::CallCleanUp, 1u>&) ConvertCall.cpp:0:0
#6 0x0000000004330d31 genProcedureRef((anonymous namespace)::CallContext&) ConvertCall.cpp:0:0
#7 0x0000000004331aa4 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-20250621/bin/flang+0x4331aa4)
#8 0x000000000454d18d hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::Type<(Fortran::common::TypeCategory)4, 1>>(Fortran::evaluate::Expr<Fortran::evaluate::Type<(Fortran::common::TypeCategory)4, 1>> const&) ConvertExprToHLFIR.cpp:0:0
#9 0x000000000454da33 hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)4>>(Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)4>> const&) ConvertExprToHLFIR.cpp:0:0
#10 0x0000000004578135 hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeType>(Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&) (.part.0) ConvertExprToHLFIR.cpp:0:0
#11 0x0000000004578415 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-20250621/bin/flang+0x4578415)
#12 0x000000000432fbc7 genProcedureRef((anonymous namespace)::CallContext&) ConvertCall.cpp:0:0
#13 0x0000000004331aa4 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-20250621/bin/flang+0x4331aa4)
#14 0x00000000043049fb (anonymous namespace)::FirConverter::genFIR(Fortran::lower::pft::Evaluation&, bool) (.constprop.0) Bridge.cpp:0:0
#15 0x000000000430961c (anonymous namespace)::FirConverter::lowerFunc(Fortran::lower::pft::FunctionLikeUnit&) Bridge.cpp:0:0
#16 0x000000000430b794 Fortran::lower::LoweringBridge::lower(Fortran::parser::Program const&, Fortran::semantics::SemanticsContext const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20250621/bin/flang+0x430b794)
#17 0x0000000004183646 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/opt/compiler-explorer/clang-llvmflang-trunk-20250621/bin/flang+0x4183646)
#18 0x0000000003ecb3c5 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20250621/bin/flang+0x3ecb3c5)
#19 0x0000000003eb9eb7 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/opt/compiler-explorer/clang-llvmflang-trunk-20250621/bin/flang+0x3eb9eb7)
#20 0x0000000003ed5523 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/opt/compiler-explorer/clang-llvmflang-trunk-20250621/bin/flang+0x3ed5523)
#21 0x0000000002216b4a fc1_main(llvm::ArrayRef<char const*>, char const*) (/opt/compiler-explorer/clang-llvmflang-trunk-20250621/bin/flang+0x2216b4a)
#22 0x00000000020c5856 main (/opt/compiler-explorer/clang-llvmflang-trunk-20250621/bin/flang+0x20c5856)
#23 0x0000795422e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#24 0x0000795422e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#25 0x0000000002215515 _start (/opt/compiler-explorer/clang-llvmflang-trunk-20250621/bin/flang+0x2215515)
flang-21: error: unable to execute command: Segmentation fault (core dumped)
flang-21: error: flang frontend command failed due to signal (use -v to see invocation)
flang version 21.0.0git (https://github.com/llvm/llvm-project.git 2dfcc4375faa5e3692bd82a022d33bdd6fe55f10)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-llvmflang-trunk-20250621/bin
flang-21: note: diagnostic msg:
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWV1znDjW_jXyjYouENDdXPiCdMw7qTdbmxpndmuvXEIcaMVCoiRht-fXb0lA0836c2Lv7FZtKunwIZ2P5zznSOhQY3gjAS5R-gmlny9ob_dKX94GVGt1by5KVT1c_gqdVlXPQKM4R2G-t7Yz7pIUiBSNqkol7ErpBpHid0SKavN7ecXkP0oU5mgdDn_rLERh3qqqF4BbFOYYc2mhAY2dqDjH3D9kSlrKpfE3GIOAFqSlAte9ZJYriWtEtgyRzI1ge6ops6AR2XJEMlyP8_DZK0RyN4HsvE5p3Wjpho-q2aRNVv-i1_SlVr3lErA50fyTOoZfFOa9GeAYwXDzqRCKUUtLAdPkH05BnA-6T7TucMVbkIYrOY8gO9wpJ-8ILYvcNCqEd8EDGCGy_eFHZ4PU0aIpXoN1nyi7tZoyGCJ_fMuUNEqAe0QK2nWIFHCgbSdg5QId5wmKc-J-8D3VksvGXRZTCDWYXljMDZZwBxpXUHMJ1RHXF6KO0isU5t--XuXXVy4-LbeY4rJvsIZOaYutwguScrvvyxVTLSKFEHfTf0Gn1Q9gFpGCG9ODQaTAVFaYSyb6CrDdA2aamj0uJyhWKMyvLWW3uOrbbgAmXKEw-6ZVo2mLqW56Z75TjxEp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