Skip to content

Segmentation fault in compiler with openmp (cuda offload mode) #130801

Open
@KaruroChori

Description

@KaruroChori

report.zip

I cannot really reduce it to a more minimal case, because even just small changes will not result in a segmentation fault.

PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21 -cc1 -triple nvptx64-nvidia-cuda -aux-triple x86_64-unknown-linux-gnu -S -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -ffp-contract=on -fno-rounding-math -no-integrated-as -fcuda-is-device -mllvm -enable-memcpyopt-without-libcalls -fno-threadsafe-statics -fcuda-allow-variadic-functions -mlink-builtin-bitcode /usr/lib/cuda/nvvm/libdevice/libdevice.10.bc -target-sdk-version=12.0 -mlink-builtin-bitcode /archive/shared/apps/cross-clang/install3/usr/local/bin/../lib/x86_64-unknown-linux-gnu/libomptarget-nvptx.bc -target-cpu sm_86 -target-feature +ptx80 -debug-info-kind=constructor -dwarf-version=2 -debugger-tuning=gdb -fno-dwarf-directory-asm -fdebug-compilation-dir=/archive/shared/projects/sdf-new-attempt/build -resource-dir /archive/shared/apps/cross-clang/install3/usr/local/lib/clang/21 -dependency-file src/app/sdl.p/main.cpp.o.d -MT src/app/sdl.p/main.cpp.o -sys-header-deps -internal-isystem /archive/shared/apps/cross-clang/install3/usr/local/lib/clang/21/include/openmp_wrappers -include __clang_openmp_device_functions.h -I src/app/sdl.p -I src/app -I ../src/app -I ../subprojects/magic_enum/include -I subprojects/magic_enum/__CMake_build -I ../subprojects/magic_enum/__CMake_build -I subprojects/magic_enum -I ../subprojects/magic_enum -I ../include -I subprojects/imgui-1.91.6 -I ../subprojects/imgui-1.91.6 -I ../subprojects/imgui-1.91.6/backends -I /usr/include/libpng16 -I /usr/local/include -D _GLIBCXX_ASSERTIONS=1 -D _FILE_OFFSET_BITS=64 -D IMGUI_API=__attribute__((visibility(\"default\"))) -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward -internal-isystem /archive/shared/apps/cross-clang/install3/usr/local/lib/clang/21/include/llvm_libc_wrappers -internal-isystem /archive/shared/apps/cross-clang/install3/usr/local/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -internal-isystem /usr/lib/cuda/include -internal-isystem /archive/shared/apps/cross-clang/install3/usr/local/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wall -Winvalid-pch -Wextra -Wpedantic -Wno-gnu-case-range -std=c++23 -fdeprecated-macro -ferror-limit 19 -fvisibility=protected -fopenmp -fopenmp-cuda-mode -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -fopenmp-is-target-device -fopenmp-host-ir-file-path /tmp/main-5817c4.bc -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/main-sm_86-ca6274.s -x c++ ../src/app/main.cpp
1.      <eof> parser at end of file
2.      ../src/app/main.cpp:190:5: LLVM IR generation of declaration 'main'
 #0 0x00005628c01defb8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1af3fb8)
 #1 0x00005628c01dcc5e llvm::sys::RunSignalHandlers() (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1af1c5e)
 #2 0x00005628c01df641 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007ff86f242990 (/lib/x86_64-linux-gnu/libc.so.6+0x42990)
 #4 0x00005628c0426a7a clang::CodeGen::CodeGenFunction::EmitStoreOfScalar(llvm::Value*, clang::CodeGen::Address, bool, clang::QualType, clang::CodeGen::LValueBaseInfo, clang::CodeGen::TBAAAccessInfo, bool, bool) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1d3ba7a)
 #5 0x00005628c042730e clang::CodeGen::CodeGenFunction::EmitStoreOfScalar(llvm::Value*, clang::CodeGen::LValue, bool) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1d3c30e)
 #6 0x00005628c0873e46 clang::CodeGen::CGOpenMPRuntimeGPU::adjustTargetSpecificDataForLambdas(clang::CodeGen::CodeGenFunction&, clang::OMPExecutableDirective const&) const (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x2188e46)
 #7 0x00005628c058b796 void clang::CodeGen::RegionCodeGenTy::CallbackFn<emitTargetTeamsRegion(clang::CodeGen::CodeGenFunction&, clang::CodeGen::PrePostActionTy&, clang::OMPTargetTeamsDirective const&)::$_0>(long, clang::CodeGen::CodeGenFunction&, clang::CodeGen::PrePostActionTy&) CGStmtOpenMP.cpp:0:0
 #8 0x00005628c04da1f0 clang::CodeGen::RegionCodeGenTy::operator()(clang::CodeGen::CodeGenFunction&) const (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1def1f0)
 #9 0x00005628c050e33b (anonymous namespace)::CGOpenMPRegionInfo::EmitBody(clang::CodeGen::CodeGenFunction&, clang::Stmt const*) CGOpenMPRuntime.cpp:0:0
#10 0x00005628c0550925 clang::CodeGen::CodeGenFunction::GenerateOpenMPCapturedStmtFunction(clang::CapturedStmt const&, clang::SourceLocation) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1e65925)
#11 0x00005628c04df101 emitParallelOrTeamsOutlinedFunction(clang::CodeGen::CodeGenModule&, clang::OMPExecutableDirective const&, clang::CapturedStmt const*, clang::VarDecl const*, llvm::omp::Directive, llvm::StringRef, clang::CodeGen::RegionCodeGenTy const&) CGOpenMPRuntime.cpp:0:0
#12 0x00005628c04df30b clang::CodeGen::CGOpenMPRuntime::emitTeamsOutlinedFunction(clang::CodeGen::CodeGenFunction&, clang::OMPExecutableDirective const&, clang::VarDecl const*, llvm::omp::Directive, clang::CodeGen::RegionCodeGenTy const&) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1df430b)
#13 0x00005628c086f1cb clang::CodeGen::CGOpenMPRuntimeGPU::emitTeamsOutlinedFunction(clang::CodeGen::CodeGenFunction&, clang::OMPExecutableDirective const&, clang::VarDecl const*, llvm::omp::Directive, clang::CodeGen::RegionCodeGenTy const&) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x21841cb)
#14 0x00005628c0575fad emitCommonOMPTeamsDirective(clang::CodeGen::CodeGenFunction&, clang::OMPExecutableDirective const&, llvm::omp::Directive, clang::CodeGen::RegionCodeGenTy const&) CGStmtOpenMP.cpp:0:0
#15 0x00005628c058b603 emitTargetTeamsRegion(clang::CodeGen::CodeGenFunction&, clang::CodeGen::PrePostActionTy&, clang::OMPTargetTeamsDirective const&) CGStmtOpenMP.cpp:0:0
#16 0x00005628c04da1f0 clang::CodeGen::RegionCodeGenTy::operator()(clang::CodeGen::CodeGenFunction&) const (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1def1f0)
#17 0x00005628c050e33b (anonymous namespace)::CGOpenMPRegionInfo::EmitBody(clang::CodeGen::CodeGenFunction&, clang::Stmt const*) CGOpenMPRuntime.cpp:0:0
#18 0x00005628c0550925 clang::CodeGen::CodeGenFunction::GenerateOpenMPCapturedStmtFunction(clang::CapturedStmt const&, clang::SourceLocation) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1e65925)
#19 0x00005628c05161b9 std::_Function_handler<llvm::Expected<llvm::Function*> (llvm::StringRef), clang::CodeGen::CGOpenMPRuntime::emitTargetOutlinedFunctionHelper(clang::OMPExecutableDirective const&, llvm::StringRef, llvm::Function*&, llvm::Constant*&, bool, clang::CodeGen::RegionCodeGenTy const&)::$_0>::_M_invoke(std::_Any_data const&, llvm::StringRef&&) CGOpenMPRuntime.cpp:0:0
#20 0x00005628c2db1ba7 llvm::OpenMPIRBuilder::emitTargetRegionFunction(llvm::TargetRegionEntryInfo&, std::function<llvm::Expected<llvm::Function*> (llvm::StringRef)>&, bool, llvm::Function*&, llvm::Constant*&) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x46c6ba7)
#21 0x00005628c04fe7e6 clang::CodeGen::CGOpenMPRuntime::emitTargetOutlinedFunctionHelper(clang::OMPExecutableDirective const&, llvm::StringRef, llvm::Function*&, llvm::Constant*&, bool, clang::CodeGen::RegionCodeGenTy const&) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1e137e6)
#22 0x00005628c086cc93 clang::CodeGen::CGOpenMPRuntimeGPU::emitTargetOutlinedFunction(clang::OMPExecutableDirective const&, llvm::StringRef, llvm::Function*&, llvm::Constant*&, bool, clang::CodeGen::RegionCodeGenTy const&) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x2181c93)
#23 0x00005628c0576248 clang::CodeGen::CodeGenFunction::EmitOMPTargetTeamsDeviceFunction(clang::CodeGen::CodeGenModule&, llvm::StringRef, clang::OMPTargetTeamsDirective const&) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1e8b248)
#24 0x00005628c050170e clang::CodeGen::CGOpenMPRuntime::scanForTargetRegionsFunctions(clang::Stmt const*, llvm::StringRef) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1e1670e)
#25 0x00005628c0501551 clang::CodeGen::CGOpenMPRuntime::scanForTargetRegionsFunctions(clang::Stmt const*, llvm::StringRef) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1e16551)
#26 0x00005628c0501551 clang::CodeGen::CGOpenMPRuntime::scanForTargetRegionsFunctions(clang::Stmt const*, llvm::StringRef) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1e16551)
#27 0x00005628c0501551 clang::CodeGen::CGOpenMPRuntime::scanForTargetRegionsFunctions(clang::Stmt const*, llvm::StringRef) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1e16551)
#28 0x00005628c0501551 clang::CodeGen::CGOpenMPRuntime::scanForTargetRegionsFunctions(clang::Stmt const*, llvm::StringRef) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1e16551)
#29 0x00005628c0501551 clang::CodeGen::CGOpenMPRuntime::scanForTargetRegionsFunctions(clang::Stmt const*, llvm::StringRef) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1e16551)
#30 0x00005628c0501551 clang::CodeGen::CGOpenMPRuntime::scanForTargetRegionsFunctions(clang::Stmt const*, llvm::StringRef) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1e16551)
#31 0x00005628c0501551 clang::CodeGen::CGOpenMPRuntime::scanForTargetRegionsFunctions(clang::Stmt const*, llvm::StringRef) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1e16551)
#32 0x00005628c0501551 clang::CodeGen::CGOpenMPRuntime::scanForTargetRegionsFunctions(clang::Stmt const*, llvm::StringRef) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1e16551)
#33 0x00005628c0501551 clang::CodeGen::CGOpenMPRuntime::scanForTargetRegionsFunctions(clang::Stmt const*, llvm::StringRef) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1e16551)
#34 0x00005628c0501551 clang::CodeGen::CGOpenMPRuntime::scanForTargetRegionsFunctions(clang::Stmt const*, llvm::StringRef) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1e16551)
#35 0x00005628c0501551 clang::CodeGen::CGOpenMPRuntime::scanForTargetRegionsFunctions(clang::Stmt const*, llvm::StringRef) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1e16551)
#36 0x00005628c0501551 clang::CodeGen::CGOpenMPRuntime::scanForTargetRegionsFunctions(clang::Stmt const*, llvm::StringRef) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1e16551)
#37 0x00005628c0501846 clang::CodeGen::CGOpenMPRuntime::emitTargetFunctions(clang::GlobalDecl) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1e16846)
#38 0x00005628c05c0543 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1ed5543)
#39 0x00005628c05bb940 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x1ed0940)
#40 0x00005628c0881b9c (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#41 0x00005628c087a328 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x218f328)
#42 0x00005628c1bc228a clang::ParseAST(clang::Sema&, bool, bool) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x34d728a)
#43 0x00005628c0ab88ed clang::FrontendAction::Execute() (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x23cd8ed)
#44 0x00005628c0a334d4 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x23484d4)
#45 0x00005628c0b7926a clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0x248e26a)
#46 0x00005628bf2928b4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0xba78b4)
#47 0x00005628bf28f501 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#48 0x00005628bf28e850 clang_main(int, char**, llvm::ToolContext const&) (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0xba3850)
#49 0x00005628bf29bda7 main (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0xbb0da7)
#50 0x00007ff86f228150 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#51 0x00007ff86f228209 call_init ./csu/../csu/libc-start.c:128:20
#52 0x00007ff86f228209 __libc_start_main ./csu/../csu/libc-start.c:347:5
#53 0x00005628bf28d295 _start (/archive/shared/apps/cross-clang/install3/usr/local/bin/clang-21+0xba2295)

[report.zip](https://github.com/user-attachments/files/19194717/report.zip)

clang++: error: unable to execute command: Segmentation fault
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 21.0.0git (https://github.com/llvm/llvm-project 1b455df780ed1d578b63f969c636fe78b2eb6014)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /archive/shared/apps/cross-clang/install3/usr/local/bin
clang++: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++: note: diagnostic msg: /tmp/main-sm_86-61c640.cpp
clang++: note: diagnostic msg: /tmp/main-0c022b.cpp
clang++: note: diagnostic msg: /tmp/main-sm_86-61c640.sh
clang++: note: diagnostic msg: 

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:codegenIR generation bugs: mangling, exceptions, etc.clang:openmpOpenMP related changes to ClangcrashPrefer [crash-on-valid] or [crash-on-invalid]

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions