[clang][OpenMP] Assertion `Idx >= 0 && "Invalid basic block argument!"' failed.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Note: using `-O3 -fopenmp -mllvm -jump-threading-across-loop-headers -fsanitize=signed-integer-overflow -mllvm -ubsan-guard-checks`
Reproducer:
https://godbolt.org/z/cxqbs7WGM
```cpp
extern void dummy (int);
void foo (void)
{
[[omp::sequence (directive (tile sizes(5, 6)),
directive (tile sizes(1, 2, 3)))]]
for (int i = 0; i < 100; ++i)
for (int j = 0; j < 100; ++j)
for (int k = 0; k < 100; ++k)
dummy (i);
}
```
Backtrace:
```console
clang++: /root/llvm-project/llvm/include/llvm/IR/Instructions.h:2817: llvm::Value* llvm::PHINode::getIncomingValueForBlock(const llvm::BasicBlock*) const: Assertion `Idx >= 0 && "Invalid basic block argument!"' failed.
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: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O3 -fopenmp -mllvm -jump-threading-across-loop-headers -fsanitize=signed-integer-overflow -mllvm -ubsan-guard-checks
1. parser at end of file
2. Optimizer
3. Running pass "require,function(invalidate),require,cgscc(devirt<4>(inline,function-attrs,argpromotion,openmp-opt-cgscc,function(sroa,early-cse,speculative-execution,jump-threading,correlated-propagation,simplifycfg,instcombine,aggressive-instcombine,libcalls-shrinkwrap,tailcallelim,simplifycfg,reassociate,constraint-elimination,loop-mssa(loop-instsimplify,loop-simplifycfg,licm,loop-rotate,licm,simple-loop-unswitch),simplifycfg,instcombine,loop(loop-idiom,indvars,extra-simple-loop-unswitch-passes,loop-deletion,loop-unroll-full),sroa,vector-combine,mldst-motion,gvn<>,sccp,bdce,instcombine,jump-threading,correlated-propagation,adce,memcpyopt,dse,move-auto-init,loop-mssa(licm),coro-elide,simplifycfg,instcombine),function-attrs,function(require),coro-split,coro-annotation-elide)),function(invalidate),cgscc(devirt<4>())" on module ""
4. Running pass "cgscc(devirt<4>(inline,function-attrs,argpromotion,openmp-opt-cgscc,function(sroa,early-cse,speculative-execution,jump-threading,correlated-propagation,simplifycfg,instcombine,aggressive-instcombine,libcalls-shrinkwrap,tailcallelim,simplifycfg,reassociate,constraint-elimination,loop-mssa(loop-instsimplify,loop-simplifycfg,licm,loop-rotate,licm,simple-loop-unswitch),simplifycfg,instcombine,loop(loop-idiom,indvars,extra-simple-loop-unswitch-passes,loop-deletion,loop-unroll-full),sroa,vector-combine,mldst-motion,gvn<>,sccp,bdce,instcombine,jump-threading,correlated-propagation,adce,memcpyopt,dse,move-auto-init,loop-mssa(licm),coro-elide,simplifycfg,instcombine),function-attrs,function(require),coro-split,coro-annotation-elide))" on module ""
5. Running pass "jump-threading" on function "_Z3foov"
#0 0x0000000004273358 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4273358)
#1 0x0000000004270784 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4270784)
#2 0x00000000041b44b8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x0000738466c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x0000738466c969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x0000738466c42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x0000738466c287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x0000738466c2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x0000738466c39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x00000000084cb8ef addPHINodeEntriesForMappedBlock(llvm::BasicBlock*, llvm::BasicBlock*, llvm::BasicBlock*, llvm::ValueMap>>&) JumpThreading.cpp:0:0
#10 0x00000000084d840b llvm::JumpThreadingPass::threadEdge(llvm::BasicBlock*, llvm::SmallVectorImpl const&, llvm::BasicBlock*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x84d840b)
#11 0x00000000084d93c5 llvm::JumpThreadingPass::threadThroughTwoBasicBlocks(llvm::BasicBlock*, llvm::BasicBlock*, llvm::BasicBlock*, llvm::BasicBlock*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x84d93c5)
#12 0x00000000084d9e32 llvm::JumpThreadingPass::maybethreadThroughTwoBasicBlocks(llvm::BasicBlock*, llvm::Value*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x84d9e32)
#13 0x00000000084da6c2 llvm::JumpThreadingPass::processThreadableEdges(llvm::Value*, llvm::BasicBlock*, llvm::jumpthreading::ConstantPreference, llvm::Instruction*) (.part.0) JumpThreading.cpp:0:0
#14 0x00000000084dbc12 llvm::JumpThreadingPass::processBlock(llvm::BasicBlock*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x84dbc12)
#15 0x00000000084dc92a llvm::JumpThreadingPass::runImpl(llvm::Function&, llvm::AnalysisManager*, llvm::TargetLibraryInfo*, llvm::TargetTransformInfo*, llvm::LazyValueInfo*, llvm::AAResults*, std::unique_ptr>, llvm::BlockFrequencyInfo*, llvm::BranchProbabilityInfo*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x84dc92a)
#16 0x00000000084dd3ad llvm::JumpThreadingPass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x84dd3ad)
#17 0x000000000451fb3e llvm::detail::PassModel>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x451fb3e)
#18 0x0000000003bc69c1 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bc69c1)
#19 0x00000000012600ce llvm::detail::PassModel>, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x12600ce)
#20 0x0000000003028172 llvm::CGSCCToFunctionPassAdaptor::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3028172)
#21 0x000000000125edee llvm::detail::PassModel, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x125edee)
#22 0x000000000301fe82 llvm::PassManager, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x301fe82)
#23 0x00000000054411de llvm::detail::PassModel, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>, llvm::AnalysisManager, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x54411de)
#24 0x0000000003024f96 llvm::DevirtSCCRepeatedPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3024f96)
#25 0x00000000054411fe llvm::detail::PassModel, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x54411fe)
#26 0x0000000003021f11 llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3021f11)
#27 0x000000000125edce llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x125edce)
#28 0x0000000003bc4a41 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bc4a41)
#29 0x0000000005b53333 llvm::ModuleInlinerWrapperPass::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5b53333)
#30 0x00000000052f1dee llvm::detail::PassModel>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52f1dee)
#31 0x0000000003bc4a41 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bc4a41)
#32 0x000000000452dcb3 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr>&, std::unique_ptr>&, clang::BackendConsumer*) BackendUtil.cpp:0:0
#33 0x0000000004531389 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr, std::unique_ptr>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4531389)
#34 0x0000000004bc1f37 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4bc1f37)
#35 0x000000000695755c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x695755c)
#36 0x0000000004bc2398 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4bc2398)
#37 0x0000000004eadba5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4eadba5)
#38 0x0000000004e2dd5e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e2dd5e)
#39 0x0000000004fa6bdd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fa6bdd)
#40 0x0000000000dc7650 cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdc7650)
#41 0x0000000000dbe0ca ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#42 0x0000000000dbe24d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#43 0x0000000004c2ab89 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#44 0x00000000041b4954 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41b4954)
#45 0x0000000004c2b19f clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#46 0x0000000004beb992 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4beb992)
#47 0x0000000004bec93e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4bec93e)
#48 0x0000000004bf3d75 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4bf3d75)
#49 0x0000000000dc3a71 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdc3a71)
#50 0x0000000000c72444 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc72444)
#51 0x0000738466c29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#52 0x0000738466c29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#53 0x0000000000dbdb65 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdbdb65)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
Contributor guide
Research direction
Start by compiling the provided C++ reproducer with the listed OpenMP, optimization, and sanitizer flags, then inspect JumpThreading.cpp around addPHINodeEntriesForMappedBlock and JumpThreadingPass::threadEdge. Confirm the failure path and determine why the PHI lookup receives an invalid basic block. Done means the reproducer no longer triggers the assertion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100