[flang] Segmentation fault when parsing nested loop in OpenMP region
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
When trying to compile the following OpenMP program flang 21 crashes with the error copied below. If I comment out the `ir` loop (L22-L24) it works.
```fortran
! mwe.F90
module mwe
implicit none
#ifdef VERBOSE_MODE
logical, private :: VERBOSE = .true.
#else
logical, private :: VERBOSE = .false.
#endif
contains
subroutine f(nd,nz,nq)
integer, intent(in) :: nd, nz, nq
integer, parameter :: ni = 2
real, allocatable :: B(:,:,:)
integer :: ib, ii
allocate(B(nz, nq, ni))
!$omp parallel do
do ib = 1, nd
if (VERBOSE) then
block
integer :: ir, ic
do ii = 1, ni
do ir = 1, nz
write(*,*) (B(ir,ic,ii),ic=1,nq)
end do
end do
end block
end if
end do
end subroutine
end module
```
```
$ flang -fopenmp mwe.f90
PLEASE submit a bug report to https://github.com/Homebrew/homebrew-core/issues and include the crash backtrace.
Stack dump:
0. Program arguments: /opt/homebrew/Cellar/flang/21.1.8/libexec/flang -fc1 -triple arm64-apple-macosx26.0.0 -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -target-cpu apple-m1 -target-feature +v8.4a -target-feature +aes -target-feature +altnzcv -target-feature +ccdp -target-feature +ccpp -target-feature +complxnum -target-feature +crc -target-feature +dotprod -target-feature +flagm -target-feature +fp-armv8 -target-feature +fp16fml -target-feature +fptoint -target-feature +fullfp16 -target-feature +jsconv -target-feature +lse -target-feature +neon -target-feature +pauth -target-feature +perfmon -target-feature +predres -target-feature +ras -target-feature +rcpc -target-feature +rdm -target-feature +sb -target-feature +sha2 -target-feature +sha3 -target-feature +specrestrict -target-feature +ssbs -fopenmp -resource-dir /opt/homebrew/opt/llvm/lib/clang/21 -mframe-pointer=non-leaf -o /var/folders/5h/txm_8yhd2n721_w7gsrvlkj8p3bpj9/T/mwe-7c2d62.o -x f95 mwe.f90
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 libLLVM.dylib 0x0000000117707118 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 libLLVM.dylib 0x000000011770795c SignalHandler(int, __siginfo*, void*) + 372
2 libsystem_platform.dylib 0x00000001885d3744 _sigtramp + 56
3 libFortranLower.dylib 0x00000001045046e8 void Fortran::lower::privatizeSymbol(Fortran::lower::AbstractConverter&, fir::FirOpBuilder&, Fortran::lower::SymMap&, llvm::SetVector, llvm::DenseSet>, 0u>&, llvm::SmallSet>&, Fortran::semantics::Symbol const*, mlir::omp::PrivateClauseOps*) + 124
4 libFortranLower.dylib 0x0000000104483cf4 Fortran::lower::omp::DataSharingProcessor::privatize(mlir::omp::PrivateClauseOps*) + 92
5 libFortranLower.dylib 0x0000000104482868 Fortran::lower::omp::DataSharingProcessor::processStep1(mlir::omp::PrivateClauseOps*) + 180
6 libFortranLower.dylib 0x000000010449ca18 genOMPDispatch(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, mlir::Location, llvm::SmallVector, 0u> const&, tomp::DirectiveWithClauses const*) + 13256
7 libFortranLower.dylib 0x00000001044a4b44 createBodyOfOp(mlir::Operation&, OpWithBodyGenInfo const&, llvm::SmallVector, 0u> const&, tomp::DirectiveWithClauses const*) + 3888
8 libFortranLower.dylib 0x000000010449e5fc genOMPDispatch(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, mlir::Location, llvm::SmallVector, 0u> const&, tomp::DirectiveWithClauses const*) + 20396
9 libFortranLower.dylib 0x00000001044a3924 genOMP(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, Fortran::parser::OpenMPLoopConstruct const&) + 660
10 libFortranLower.dylib 0x0000000104496f5c Fortran::lower::genOpenMPConstruct(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, Fortran::parser::OpenMPConstruct const&) + 200
11 libFortranLower.dylib 0x000000010404f2d0 void Fortran::common::log2visit::Log2VisitHelper<83ul, 93ul, void, Fortran::common::visitors::visit<(anonymous namespace)::FirConverter::genFIR(Fortran::lower::pft::Evaluation&, bool)::'lambda'(auto const&)>(auto&&) const::'lambda'(auto)>, std::__1::variant, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const> const&>(Fortran::common::visitors::visit<(anonymous namespace)::FirConverter::genFIR(Fortran::lower::pft::Evaluation&, bool)::'lambda'(auto const&)>(auto&&) const::'lambda'(auto)>&&, unsigned long, std::__1::variant, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const, Fortran::parser::AllocateStmt const> const&) + 716
12 libFortranLower.dylib 0x0000000104044560 (anonymous namespace)::FirConverter::lowerFunc(Fortran::lower::pft::FunctionLikeUnit&) + 492
13 libFortranLower.dylib 0x0000000104043f8c Fortran::lower::LoweringBridge::lower(Fortran::parser::Program const&, Fortran::semantics::SemanticsContext const&) + 1100
14 libflangFrontend.dylib 0x0000000102771f54 Fortran::frontend::CodeGenAction::beginSourceFileAction() + 1136
15 libflangFrontend.dylib 0x000000010276f2d0 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) + 356
16 libflangFrontend.dylib 0x0000000102681798 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) + 812
17 libflangFrontendTool.dylib 0x0000000102417408 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) + 4304
18 flang-21 0x00000001023e35c0 fc1_main(llvm::ArrayRef, char const*) + 708
19 flang-21 0x00000001023e2238 main + 700
20 dyld 0x0000000188201d54 start + 7184
flang-21: error: unable to execute command: Segmentation fault: 11
flang-21: error: flang frontend command failed due to signal (use -v to see invocation)
Homebrew flang version 21.1.8
Target: arm64-apple-darwin25.2.0
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/flang/21.1.8/libexec
Configuration file: /opt/homebrew/Cellar/flang/21.1.8/libexec/flang.cfg
Configuration file: /opt/homebrew/etc/clang/arm64-apple-darwin25.cfg
flang-21: note: diagnostic msg:
********************
```
Contributor guide
Assessment
This issue has not been assessed yet.