llvm / llvm/llvm-project

[flang][OpenMP] Fortran block construct in OpenMP region

Open
#187,476 2 comments 0 reactions 0 assignees View on GitHub
flang:openmp
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The following program leads to segmentation fault in the frontend:

```fortran
! omp_01.F90
module lw
implicit none
private
public :: stream
contains
subroutine stream(nx,ny,fsrc,fdst,w)
integer, intent(in), value :: nx, ny
real(8), intent(in) :: fsrc(0:ny+1,0:nx+1,0:8), w(-1:1,-1:1,1:8)
real(8), intent(inout) :: fdst(0:ny+1,0:nx+1,0:8)
integer :: i, j, k
!$omp parallel if(nx*ny > 100**2) default(private) &
!$omp shared(nx,ny,fsrc,fdst) firstprivate(w)
!$omp do collapse(2) schedule(static)
do k = 1, 8
do j = 1, nx
do i = 1, ny
block
real(8) :: delta
delta = sum(w(-1:1,-1:1,k)*fsrc(i-1:i+1,j-1:j+1,k))
fdst(i,j,k) = fsrc(i,j,k) + delta
end block
end do
end do
end do
!$omp end do
!$omp end parallel
end subroutine
end module
```

When compiled with `flang -c -fopenmp -fopenmp-version=51 omp_01.F90` I get,

```
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 -fopenmp-version=51 -resource-dir /opt/homebrew/opt/llvm/lib/clang/21 -mframe-pointer=non-leaf -o /var/folders/5h/txm_8yhd2n721_w7gsrvlkj8p3bpj9/T/omp_01-062192.o -x f95 omp_01.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 0x0000000119eaf118 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 libLLVM.dylib 0x0000000119eaf95c SignalHandler(int, __siginfo*, void*) + 372
2 libsystem_platform.dylib 0x000000018f8ad764 _sigtramp + 56
3 libFortranLower.dylib 0x0000000106cac6e8 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 0x0000000106c2bcf4 Fortran::lower::omp::DataSharingProcessor::privatize(mlir::omp::PrivateClauseOps*) + 92
5 libFortranLower.dylib 0x0000000106c2a868 Fortran::lower::omp::DataSharingProcessor::processStep1(mlir::omp::PrivateClauseOps*) + 180
6 libFortranLower.dylib 0x0000000106c44df8 genOMPDispatch(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, mlir::Location, llvm::SmallVector, 0u> const&, tomp::DirectiveWithClauses const*) + 14248
7 libFortranLower.dylib 0x0000000106c3fcb0 Fortran::lower::genOpenMPConstruct(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, Fortran::parser::OpenMPConstruct const&) + 3612
8 libFortranLower.dylib 0x00000001067f72d0 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
9 libFortranLower.dylib 0x00000001067ec560 (anonymous namespace)::FirConverter::lowerFunc(Fortran::lower::pft::FunctionLikeUnit&) + 492
10 libFortranLower.dylib 0x00000001067ebf8c Fortran::lower::LoweringBridge::lower(Fortran::parser::Program const&, Fortran::semantics::SemanticsContext const&) + 1100
11 libflangFrontend.dylib 0x0000000104f19f54 Fortran::frontend::CodeGenAction::beginSourceFileAction() + 1136
12 libflangFrontend.dylib 0x0000000104f172d0 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) + 356
13 libflangFrontend.dylib 0x0000000104e29798 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) + 812
14 libflangFrontendTool.dylib 0x0000000104bfb408 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) + 4304
15 flang-21 0x0000000104bc75c0 fc1_main(llvm::ArrayRef, char const*) + 708
16 flang-21 0x0000000104bc6238 main + 700
17 dyld 0x000000018f4d9d54 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.3.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:
```

The preprocessed source and reproducer,
* [omp_01-8ae189.txt](https://github.com/user-attachments/files/26113006/omp_01-8ae189.txt)
* [omp_01-8ae189.sh](https://github.com/user-attachments/files/26112999/omp_01-8ae189.sh)

It does not crash if I omit the `block`/`end block`.

Contributor guide

Open the contributing guide

Research direction

Reproduce with `flang -c -fopenmp -fopenmp-version=51 omp_01.F90` using the supplied program. Start at `privatizeSymbol`, `DataSharingProcessor::privatize`, and `genOMPDispatch` in the stack trace, then trace the block construct through `genOpenMPConstruct`. Done means this reproducer no longer segfaults during compilation and has regression coverage for the failure.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.