Skip to content

[Clang][OpenMP] Clang crashes with OpenMP reduction pragma #77535

Closed
@rkchang

Description

@rkchang

I simplified the arguments a bit and ran it through godbolt: https://godbolt.org/z/W6Y587bKK

Here's the original:
Preprocessed source

# 1 "<built-in>"
# 1 "ret134_8bb3be45-13a1-47e9-a46d-089a2e34d440.c"
int
foo ()
{
  int r = 0;
  #pragma omp scope reduction(+:r)      /* { dg-error "reduction variable 'r' is private in outer context" } */
  r++;
  return r;
}

Run script

# Crash reproducer for clang version 18.0.0git ([email protected]:llvm/llvm-project.git 25e0dc92a1df906d6e42c66a32f1fa764f1acabd)
# Driver args: "-c" "-fopenmp" "-fcrash-diagnostics-dir=trigger/diagnostics" "-fsanitize=undefined,address" "ret134_8bb3be45-13a1-47e9-a46d-089a2e34d440.c" "-o" "/tmp/exe_tid7.o"
# Original command:  "/home/rkchang/dev/omp/compilers/llvm_install/bin/clang-18" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "ret134_8bb3be45-13a1-47e9-a46d-089a2e34d440.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/home/rkchang/dev/omp/trigger/clang" "-mllvm" "-crash-diagnostics-dir=trigger/diagnostics" "-fcoverage-compilation-dir=/home/rkchang/dev/omp/trigger/clang" "-resource-dir" "/home/rkchang/dev/omp/compilers/llvm_install/lib/clang/18" "-internal-isystem" "/home/rkchang/dev/omp/compilers/llvm_install/lib/clang/18/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-ferror-limit" "19" "-fopenmp" "-fsanitize=address,alignment,array-bounds,bool,builtin,enum,float-cast-overflow,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound,vptr" "-fsanitize-recover=alignment,array-bounds,bool,builtin,enum,float-cast-overflow,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,vla-bound,vptr" "-fno-sanitize-memory-param-retval" "-fsanitize-address-use-after-scope" "-fsanitize-address-globals-dead-stripping" "-fno-assume-sane-operator-new" "-fgnuc-version=4.2.1" "-fcolor-diagnostics" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "/tmp/exe_tid7.o" "-x" "c" "ret134_8bb3be45-13a1-47e9-a46d-089a2e34d440.c"
 "/home/rkchang/dev/omp/compilers/llvm_install/bin/clang-18" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "ret134_8bb3be45-13a1-47e9-a46d-089a2e34d440.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/home/rkchang/dev/omp/trigger/clang" "-mllvm" "-crash-diagnostics-dir=trigger/diagnostics" "-fcoverage-compilation-dir=/home/rkchang/dev/omp/trigger/clang" "-ferror-limit" "19" "-fopenmp" "-fsanitize=address,alignment,array-bounds,bool,builtin,enum,float-cast-overflow,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound,vptr" "-fsanitize-recover=alignment,array-bounds,bool,builtin,enum,float-cast-overflow,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,vla-bound,vptr" "-fno-sanitize-memory-param-retval" "-fsanitize-address-use-after-scope" "-fsanitize-address-globals-dead-stripping" "-fno-assume-sane-operator-new" "-fgnuc-version=4.2.1" "-fcolor-diagnostics" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c" "ret134_8bb3be45-13a1-47e9-a46d-089a2e34d440-3e7b76.c"
❯ ~/dev/omp/compilers/llvm_install/bin/clang -c -fopenmp -fcrash-diagnostics-dir='trigger/diagnostics' -fsanitize=undefined,address ret134_8bb3be45-13a1-47e9-a46d-089a2e34d440.c -o /tmp/exe_tid7.o

scope not supported with FE outlining
UNREACHABLE executed at /home/rkchang/dev/omp/compilers/llvm-project/clang/lib/CodeGen/CGStmt.cpp:413!
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: /home/rkchang/dev/omp/compilers/llvm_install/bin/clang -c -fopenmp -fcrash-diagnostics-dir=trigger/diagnostics -fsanitize=undefined,address ret134_8bb3be45-13a1-47e9-a46d-089a2e34d440.c -o /tmp/exe_tid7.o
1.      <eof> parser at end of file
2.      Per-file LLVM IR generation
3.      ret134_8bb3be45-13a1-47e9-a46d-089a2e34d440.c:5:1: Generating code for declaration 'foo'
 #0 0x0000563ab1ecab50 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x418db50)
 #1 0x0000563ab1ec7f5f llvm::sys::RunSignalHandlers() (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x418af5f)
 #2 0x0000563ab1e0c178 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f0daa242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f0daa2969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007f0daa2969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007f0daa2969fc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007f0daa242476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007f0daa2287f3 abort ./stdlib/abort.c:81:7
 #9 0x0000563ab1e167be (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x40d97be)
#10 0x0000563ab22510e9 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x45140e9)
#11 0x0000563ab2257054 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x451a054)
#12 0x0000563ab2224ff5 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x44e7ff5)
#13 0x0000563ab2238c54 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x44fbc54)
#14 0x0000563ab21deb79 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x44a1b79)
#15 0x0000563ab21d8b75 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x449bb75)
#16 0x0000563ab21e400b clang::CodeGen::CodeGenModule::EmitDeferred() (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x44a700b)
#17 0x0000563ab21e6844 clang::CodeGen::CodeGenModule::Release() (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x44a9844)
#18 0x0000563ab284e0d2 (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#19 0x0000563ab284ca33 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x4b0fa33)
#20 0x0000563ab4704409 clang::ParseAST(clang::Sema&, bool, bool) (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x69c7409)
#21 0x0000563ab2c2fe39 clang::FrontendAction::Execute() (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x4ef2e39)
#22 0x0000563ab2ba75d5 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x4e6a5d5)
#23 0x0000563ab2d0ab95 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x4fcdb95)
#24 0x0000563ab091fff9 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x2be2ff9)
#25 0x0000563ab0917863 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#26 0x0000563ab29e871d void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#27 0x0000563ab1e0c640 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x40cf640)
#28 0x0000563ab29e8f9e clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#29 0x0000563ab29aa05a clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x4c6d05a)
#30 0x0000563ab29aab2d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x4c6db2d)
#31 0x0000563ab29b6624 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x4c79624)
#32 0x0000563ab091cda0 clang_main(int, char**, llvm::ToolContext const&) (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x2bdfda0)
#33 0x0000563ab092d343 main (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x2bf0343)
#34 0x00007f0daa229d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#35 0x00007f0daa229e40 call_init ./csu/../csu/libc-start.c:128:20
#36 0x00007f0daa229e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#37 0x0000563ab09164a5 _start (/home/rkchang/dev/omp/compilers/llvm_install/bin/clang+0x2bd94a5)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 18.0.0git ([email protected]:llvm/llvm-project.git 25e0dc92a1df906d6e42c66a32f1fa764f1acabd)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/rkchang/dev/omp/compilers/llvm_install/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: trigger/diagnostics/ret134_8bb3be45-13a1-47e9-a46d-089a2e34d440-4ea7e8.c
clang: note: diagnostic msg: trigger/diagnostics/ret134_8bb3be45-13a1-47e9-a46d-089a2e34d440-4ea7e8.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]good first issuehttps://github.com/llvm/llvm-project/contribute

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions