-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Closed
Labels
clang:codegenIR generation bugs: mangling, exceptions, etc.IR generation bugs: mangling, exceptions, etc.crashPrefer [crash-on-valid] or [crash-on-invalid]Prefer [crash-on-valid] or [crash-on-invalid]openmp
Description
The following program crashes from executing an llvm_unreachable
instruction. This is caused by the captured variable not having an entry in the local declaration map. Here is a godbolt link and the following reproducer https://godbolt.org/z/x6b935zG5.
template <int T> class A {
double *ptr = nullptr;
public:
void foo() {
#pragma omp target data use_device_ptr(ptr)
{ double *capture = ptr; }
}
};
template class A<0>;
This is all that is required to reproduce this bug.
$ clang++ bug.cpp -fopenmp
DeclRefExpr for Decl not entered in LocalDeclMap?
UNREACHABLE executed at clang/lib/CodeGen/CGExpr.cpp:2876!
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: clang++ bug.cpp -fopenmp -c
1. <eof> parser at end of file
2. Per-file LLVM IR generation
3. bug.cpp:5:8: Generating code for declaration 'A<0>::foo'
#0 0x00007f000f221ace llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/jhuber/Documents/llvm/clang/lib/libLLVMSupport.so.17git+0x221ace)
#1 0x00007f000f21f38b llvm::sys::RunSignalHandlers() (/home/jhuber/Documents/llvm/clang/lib/libLLVMSupport.so.17git+0x21f38b)
#2 0x00007f000f12d528 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007f000ea51f50 (/usr/lib/libc.so.6+0x38f50)
#4 0x00007f000eaa08ec (/usr/lib/libc.so.6+0x878ec)
#5 0x00007f000ea51ea8 raise (/usr/lib/libc.so.6+0x38ea8)
#6 0x00007f000ea3b53d abort (/usr/lib/libc.so.6+0x2253d)
#7 0x00007f000f146cfa (/home/jhuber/Documents/llvm/clang/lib/libLLVMSupport.so.17git+0x146cfa)
#8 0x00007f001390ce8d clang::CodeGen::CodeGenFunction::EmitDeclRefLValue(clang::DeclRefExpr const*) (/home/jhuber/Documents/llvm/clang/lib/libclangCodeGen.so.17git+0x50ce8d)
#9 0x00007f0013908098 clang::CodeGen::CodeGenFunction::EmitLValueHelper(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/home/jhuber/Documents/llvm/clang/lib/libclangCodeGen.so.17git+0x508098)
#10 0x00007f0013908690 clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/home/jhuber/Documents/llvm/clang/lib/libclangCodeGen.so.17git+0x508690)
#11 0x00007f0013ad683d (anonymous namespace)::OMPLexicalScope::OMPLexicalScope(clang::CodeGen::CodeGenFunction&, clang::OMPExecutableDirective const&, std::optional<llvm::omp::Directive>, bool) (.isra.0) CGStmtOpenMP.cpp:0:0
#12 0x00007f0013b03373 clang::CodeGen::CodeGenFunction::EmitOMPTargetDataDirective(clang::OMPTargetDataDirective const&)::'lambda'(clang::CodeGen::CodeGenFunction&, clang::CodeGen::PrePostActionTy&)::operator()(clang::CodeGen::CodeGenFunction&, clang::CodeGen::PrePostActionTy&) const::'lambda0'(clang::CodeGen::CodeGenFunction&, clang::CodeGen::PrePostActionTy&)::operator()(clang::CodeGen::CodeGenFunction&, clang::CodeGen::PrePostActionTy&) const CGStmtOpenMP.cpp:0:0
It seems that the templated OMPCaputeredExprDecl
that is captured in the region does not have an accompanying address in the variable map. So, when we try to emit an L-value on it, we fail to get its address because it was never set. I'm unsure what the proper course of action here would be.
Metadata
Metadata
Assignees
Labels
clang:codegenIR generation bugs: mangling, exceptions, etc.IR generation bugs: mangling, exceptions, etc.crashPrefer [crash-on-valid] or [crash-on-invalid]Prefer [crash-on-valid] or [crash-on-invalid]openmp