Issue |
127762
|
Summary |
[clang] Crash at -O2: Assertion `i < getNumSuccessors() && "Successo r # out of range for Branch!"' failed.
|
Labels |
clang
|
Assignees |
|
Reporter |
cardigan1008
|
This code crashes at `-O2`:
```c
int a, b, d, e, f, h;
int i(int o, int q[], int r[]) {
for (int g = 0; g < o; g++)
if (q[g])
if (r[g])
return 0;
return 1;
}
int s() {
a = 0;
switch (d) {
case 3:
return 0;
case 43:
case 2:
case 9:
return 1;
}
}
int u() {
long p = s();
b = p;
return 0;
}
int v(int o, int q) {
int t, j = 0, k = 0;
int l[] = {0, k, 4, 1, 0, 4, k, 2, k, 7, 9, 7, 7, 2, 9, 3, 6, 6, k, 4};
int m[] = {j, j, 6, 8, j, 5, 4, 9, 7, 5, j, 9, 1, j, 3, 3};
int n = i(o, l, m);
if (n + o)
t = q + 1;
return t;
}
void w() {
int c = 0;
for (; c + a < u() + f; c++)
if (0 == v(f, e) + c) {
h = c;
break;
}
}
void main() {}
```
Compiler Explorer: https://godbolt.org/z/esW1xq3nP
Bisected to https://github.com/llvm/llvm-project/commit/38376dee92224c6657ef6d88413bfc77f4441268, which was committed by @fhahn
Crash:
```console
clang: /root/llvm-project/llvm/include/llvm/IR/Instructions.h:3117: llvm::BasicBlock* llvm::BranchInst::getSuccessor(unsigned int) const: Assertion `i < getNumSuccessors() && "Successor # out of range for Branch!"' failed.
```
Backtrace:
```console
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -gdwarf-4 -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 -O2 <source>
1. <eof> parser at end of file
2. Optimizer
3. Running pass "function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)" on module "<source>"
4. Running pass "loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>" on function "w"
#0 0x0000000003e9f068 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e9f068)
#1 0x0000000003e9cd24 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e9cd24)
#2 0x0000000003de9128 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x0000766dece42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x0000766dece969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x0000766dece42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x0000766dece287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x0000766dece2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x0000766dece39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x0000000005b93fce (anonymous namespace)::PlainCFGBuilder::buildPlainCFG(llvm::DenseMap<llvm::VPBlockBase*, llvm::BasicBlock*, llvm::DenseMapInfo<llvm::VPBlockBase*, void>, llvm::detail::DenseMapPair<llvm::VPBlockBase*, llvm::BasicBlock*>>&) VPlanHCFGBuilder.cpp:0:0
#10 0x0000000005b9432b llvm::VPlanHCFGBuilder::buildPlainCFG() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5b9432b)
#11 0x0000000005b943b2 llvm::VPlanHCFGBuilder::buildHierarchicalCFG() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5b943b2)
#12 0x0000000005a4d231 llvm::LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(llvm::VFRange&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5a4d231)
#13 0x0000000005a5035a llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5a5035a)
#14 0x0000000005a508a7 llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5a508a7)
#15 0x0000000005a522df llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5a522df)
#16 0x0000000005a549a9 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5a549a9)
#17 0x0000000005a55023 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5a55023)
#18 0x000000000557565e llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x557565e)
#19 0x00000000038433c0 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x38433c0)
#20 0x00000000011b9b4e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x11b9b4e)
#21 0x0000000003841cdb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3841cdb)
#22 0x00000000011b8e9e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x11b8e9e)
#23 0x00000000038416e0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x38416e0)
#24 0x000000000415c764 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0
#25 0x000000000416021e clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x416021e)
#26 0x0000000004860280 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4860280)
#27 0x00000000064ac8bc clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x64ac8bc)
#28 0x0000000004860688 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4860688)
#29 0x0000000004b274b5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4b274b5)
#30 0x0000000004aaae6e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4aaae6e)
#31 0x0000000004c15f0e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c15f0e)
#32 0x0000000000d6562f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd6562f)
#33 0x0000000000d5d0aa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#34 0x00000000048a6c99 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
#35 0x0000000003de95d4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3de95d4)
#36 0x00000000048a728f 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
#37 0x000000000486a40d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x486a40d)
#38 0x000000000486b48e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x486b48e)
#39 0x0000000004873445 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4873445)
#40 0x0000000000d62423 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd62423)
#41 0x0000000000c2b604 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc2b604)
#42 0x0000766dece29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#43 0x0000766dece29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#44 0x0000000000d5cb55 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd5cb55)
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs