Open
Description
Testing flang with SPEC Accel OMP in a multicore compilation highlighted the following issue where the compiler segfaults during compilation of an openmp region.
test.f90:
program crash_repro
implicit none
real :: a(10, 70, 10)
integer :: i, j, k, n
n = 1
a = 0
!$omp target
!$omp teams
!$omp distribute parallel do collapse(2)
do i = 1,10
do j = 1,10
do k = 1,10
a(k,57,n) = a(k,57,n) - 0.5
end do
end do
end do
a(1,57,n) = a(2,57,n)
!$omp end teams
!$omp end target
end program crash_repro
Backtrace from compilation with a recent upstream Flang:
scamp@dev-sky5:/local/home/scamp/551.ppalm_0$ flang --version
flang version 21.0.0git (https://github.com/llvm/llvm-project b54cfa46a7eba293b6f2086856a36cc553444939)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /proj/nv/llvm/Linux_x86_64/llvm-5551/bin
Build config: +assertions
scamp@dev-sky5:/local/home/scamp/551.ppalm_0$ flang test.f90 -o test -fopenmp -fopenmp-version=50
warning: OpenMP support for version 50 in flang is still incomplete
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /proj/nv/llvm/Linux_x86_64/llvm-5551/bin/flang -fc1 -triple x86_64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -fopenmp -fopenmp-version=50 -resource-dir /proj/nv/llvm/Linux_x86_64/llvm-5551/lib/clang/21 -mframe-pointer=all -o /tmp/test-667a08.o -x f95 test.f90
#0 0x0000000004e494b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/proj/nv/llvm/Linux_x86_64/llvm-5551/bin/flang+0x4e494b8)
#1 0x0000000004e46354 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#2 0x00000befa6a45320 (/lib/x86_64-linux-gnu/libc.so.6+0x45320)
#3 0x0000000009922ba1 llvm::OpenMPIRBuilder::calculateCanonicalLoopTripCount(llvm::OpenMPIRBuilder::LocationDescription const&, llvm::Value*, llvm::Value*, llvm::Value*, bool, bool, llvm::Twine const&) (/proj/nv/llvm/Linux_x86_64/llvm-5551/bin/flang+0x9922ba1)
#4 0x0000000006dc51a8 convertOmpTarget(mlir::Operation&, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) OpenMPToLLVMIRTranslation.cpp:0:0
#5 0x0000000006ddbb6a convertHostOrTargetOperation(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) OpenMPToLLVMIRTranslation.cpp:0:0
#6 0x0000000006ddc8ce (anonymous namespace)::OpenMPDialectLLVMIRTranslationInterface::convertOperation(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) const OpenMPToLLVMIRTranslation.cpp:0:0
#7 0x0000000008b00fae mlir::LLVM::ModuleTranslation::convertOperation(mlir::Operation&, llvm::IRBuilderBase&, bool) (/proj/nv/llvm/Linux_x86_64/llvm-5551/bin/flang+0x8b00fae)
#8 0x0000000008b0acf7 mlir::LLVM::ModuleTranslation::convertBlockImpl(mlir::Block&, bool, llvm::IRBuilderBase&, bool) (/proj/nv/llvm/Linux_x86_64/llvm-5551/bin/flang+0x8b0acf7)
#9 0x0000000008b0c6f8 mlir::LLVM::ModuleTranslation::convertOneFunction(mlir::LLVM::LLVMFuncOp) (/proj/nv/llvm/Linux_x86_64/llvm-5551/bin/flang+0x8b0c6f8)
#10 0x0000000008b0d914 mlir::LLVM::ModuleTranslation::convertFunctions() (/proj/nv/llvm/Linux_x86_64/llvm-5551/bin/flang+0x8b0d914)
#11 0x0000000008b179b5 mlir::translateModuleToLLVMIR(mlir::Operation*, llvm::LLVMContext&, llvm::StringRef, bool) (/proj/nv/llvm/Linux_x86_64/llvm-5551/bin/flang+0x8b179b5)
#12 0x0000000004ea9bef Fortran::frontend::CodeGenAction::generateLLVMIR() (/proj/nv/llvm/Linux_x86_64/llvm-5551/bin/flang+0x4ea9bef)
#13 0x0000000004eae458 Fortran::frontend::CodeGenAction::executeAction() (/proj/nv/llvm/Linux_x86_64/llvm-5551/bin/flang+0x4eae458)
#14 0x0000000004e8fddd Fortran::frontend::FrontendAction::execute() (/proj/nv/llvm/Linux_x86_64/llvm-5551/bin/flang+0x4e8fddd)
#15 0x0000000004e6cc0b Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/proj/nv/llvm/Linux_x86_64/llvm-5551/bin/flang+0x4e6cc0b)
#16 0x0000000004e98d67 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/proj/nv/llvm/Linux_x86_64/llvm-5551/bin/flang+0x4e98d67)
#17 0x0000000004767220 fc1_main(llvm::ArrayRef<char const*>, char const*) (/proj/nv/llvm/Linux_x86_64/llvm-5551/bin/flang+0x4767220)
#18 0x00000000047668f8 main (/proj/nv/llvm/Linux_x86_64/llvm-5551/bin/flang+0x47668f8)
#19 0x00000befa6a2a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#20 0x00000befa6a2a28b call_init ./csu/../csu/libc-start.c:128:20
#21 0x00000befa6a2a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#22 0x0000000004764f6e _start (/proj/nv/llvm/Linux_x86_64/llvm-5551/bin/flang+0x4764f6e)
flang-21: error: unable to execute command: Segmentation fault
flang-21: error: flang frontend command failed due to signal (use -v to see invocation)
"crash reproducer file" generated:
# Crash reproducer for clang version 21.0.0git (https://github.com/llvm/llvm-project b54cfa46a7eba293b6f2086856a36cc553444939)
# Driver args: "test.f90" "-o" "test" "-fopenmp" "-fopenmp-version=50"
# Original command: "/proj/nv/llvm/Linux_x86_64/llvm-5551/bin/flang" "-fc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-fcolor-diagnostics" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-target-cpu" "x86-64" "-fopenmp" "-fopenmp-version=50" "-resource-dir" "/proj/nv/llvm/Linux_x86_64/llvm-5551/lib/clang/21" "-mframe-pointer=all" "-o" "/tmp/test-667a08.o" "-x" "f95" "test.f90"
"/proj/nv/llvm/Linux_x86_64/llvm-5551/bin/flang" "-fc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-fcolor-diagnostics" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-target-cpu" "x86-64" "-fopenmp" "-fopenmp-version=50" "-mframe-pointer=all" "-x" "f95" "test-13da17"
Note that if I remove the second update of "a" after the triply nested do loop, the code doesn't crash. Also note that if instead of an explicit target region and teams region, I make th