[VPlan] Crash at -O2/s: Segmentation fault in VPValue::getUnderlyingValue() during removeDeadRecipes
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Compiler Explorer: https://godbolt.org/z/ee1ndE3rd
small.c
```c
int *a;
int b;
long c(int d) {
int e = 8;
long f = d ? 0 : 1;
do {
int g = *(a + f);
e = g > e ? g : e;
a[7] = 0;
} while (++f < 5 && (unsigned)d > 0);
return e;
}
void h() {
long i[2];
int j = 0;
for (; j < 9; j++)
b = *(i + 2);
i[c(j - 57)] = 0;
}
int main() {}
```
Reproduce:
```
$ clang-trunk -O2 small.c
```
Stack dump:
```
0. Program arguments: /data/x27zhou/compiler-nightly/install/llvm/bin/clang-24 -cc1 -triple x86_64-unknown-linux-gnu -O2 -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -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/x27zhou/argus/fuzz-results/run-20260911-2018-24h-72w-iter8/bugs/crash_1109_w5qkdY9L -fcoverage-compilation-dir=/home/x27zhou/argus/fuzz-results/run-20260911-2018-24h-72w-iter8/bugs/crash_1109_w5qkdY9L -resource-dir /data/x27zhou/compiler-nightly/install/llvm/lib/clang/24 -internal-isystem /data/x27zhou/compiler-nightly/install/llvm/lib/clang/24/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 -fmessage-length=149 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -vectorize-loops -vectorize-slp -faddrsig -fdwarf2-cfi-asm -o /tmp/small-0163ac.o -x c small.c
1. parser at end of file
2. Optimizer
3. Running pass "function(drop-unnecessary-assumes,float2int,lower-constant-intrinsics,loop(loop-rotate,loop-deletion,loop-interchange),loop-distribute,inject-tli-mappings,loop-vectorize,drop-unnecessary-assumes,infer-alignment,loop-load-elim,instcombine,simplifycfg,slp-vectorizer,vector-combine,instcombine,loop-unroll,transform-warning,sroa,infer-alignment,instcombine,loop-mssa(licm),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,mergeicmps,expand-memcmp,tailcallelim,simplifycfg)" on module "small.c"
4. Running pass "loop-vectorize" on function "h"
#0 0x0000556dfee4d2fa llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:931:13
#1 0x0000556dfee4af0a llvm::sys::RunSignalHandlers() /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Support/Signals.cpp:109:18
#2 0x0000556dfee4dddb SignalHandler(int, siginfo_t*, void*) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:474:38
#3 0x0000556dfee4dc38 int const* std::__find_if>(int const*, int const*, __gnu_cxx::__ops::_Iter_equals_val, std::random_access_iterator_tag) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_algobase.h:2067:8
#4 0x0000556dfee4dc38 int const* std::__find_if>(int const*, int const*, __gnu_cxx::__ops::_Iter_equals_val) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_algobase.h:2112:14
#5 0x0000556dfee4dc38 int const* std::find(int const*, int const*, int const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_algo.h:3851:14
#6 0x0000556dfee4dc38 bool llvm::is_contained(int const (&) [10], int const&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/ADT/STLExtras.h:1953:12
#7 0x0000556dfee4dc38 SignalHandlerTerminate(int, siginfo_t*, void*) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:514:7
#8 0x00007fd5d96cf520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#9 0x0000556dff0df1eb llvm::SmallVectorBase::size() const /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/ADT/SmallVector.h:83:32
#10 0x0000556dff0df1eb llvm::TinyPtrVector::size() const /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/ADT/TinyPtrVector.h:145:32
#11 0x0000556dff0df1eb llvm::VPDef::getVPSingleValue() const /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/VPlanValue.h:558:5
#12 0x0000556dff0df493 llvm::VPValue::getUnderlyingValue() const /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/VPlanValue.h:75:46
#13 0x0000556dff0df493 llvm::VPRecipeBase::mayHaveSideEffects() const /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp:219:59
#14 0x0000556dff16b026 llvm::vputils::isDeadRecipe(llvm::VPRecipeBase&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp:1121:7
#15 0x0000556dff10c12d llvm::VPlanTransforms::removeDeadRecipes(llvm::VPlan&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp:754:11
#16 0x0000556dff03776c llvm::cl::opt_storage::getValue() const /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/Support/CommandLine.h:1455:38
#17 0x0000556dff03776c llvm::cl::opt_storage::operator bool() const /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/Support/CommandLine.h:1459:38
#18 0x0000556dff03776c decltype(auto) llvm::VPlanTransforms::runPass(llvm::StringRef, void (&)(llvm::VPlan&), llvm::VPlan&)::'lambda'()::operator()() const /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/VPlanTransforms.h:101:11
#19 0x0000556dff03776c llvm::scope_exit(llvm::StringRef, void (&)(llvm::VPlan&), llvm::VPlan&)::'lambda'()>::~scope_exit() /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/ADT/ScopeExit.h:42:7
#20 0x0000556dff03776c decltype(auto) llvm::VPlanTransforms::runPass(llvm::StringRef, void (&)(llvm::VPlan&), llvm::VPlan&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/VPlanTransforms.h:111:3
#21 0x0000556dff113869 llvm::VPlanTransforms::optimize(llvm::VPlan&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp:2687:3
#22 0x0000556dff03776c llvm::cl::opt_storage::getValue() const /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/Support/CommandLine.h:1455:38
#23 0x0000556dff03776c llvm::cl::opt_storage::operator bool() const /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/Support/CommandLine.h:1459:38
#24 0x0000556dff03776c decltype(auto) llvm::VPlanTransforms::runPass(llvm::StringRef, void (&)(llvm::VPlan&), llvm::VPlan&)::'lambda'()::operator()() const /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/VPlanTransforms.h:101:11
#25 0x0000556dff03776c llvm::scope_exit(llvm::StringRef, void (&)(llvm::VPlan&), llvm::VPlan&)::'lambda'()>::~scope_exit() /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/ADT/ScopeExit.h:42:7
#26 0x0000556dff03776c decltype(auto) llvm::VPlanTransforms::runPass(llvm::StringRef, void (&)(llvm::VPlan&), llvm::VPlan&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/VPlanTransforms.h:111:3
#27 0x0000556dff032352 std::__uniq_ptr_impl>::_M_ptr() const/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/unique_ptr.h:191:51
#28 0x0000556dff032352 std::unique_ptr>::get() const /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/unique_ptr.h:462:21
#29 0x0000556dff032352 std::unique_ptr>::operator->() const /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/unique_ptr.h:455:9
#30 0x0000556dff032352 llvm::LoopVectorizationPlanner::buildVPlans(llvm::VPlan&, llvm::ElementCount, llvm::ElementCount) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:6537:9
#31 0x0000556dff03116e llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:5388:3
#32 0x0000556dff047aa0 llvm::LoopVectorizePass::processLoop(llvm::Loop*) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:0:7
#33 0x0000556dff051a14 llvm::LoopVectorizePass::runImpl(llvm::Function&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:8291:30
#34 0x0000556dff0527b0 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:0:32
#35 0x0000556dffd93a2d llvm::detail::PassModel>::runImpl(llvm::detail::PassConcept>&, llvm::Function&, llvm::AnalysisManager&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:128:5
#36 0x0000556dfe83454b llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:80:8
#37 0x0000556dfc4e7a7d llvm::detail::PassModel>, llvm::AnalysisManager>::runImpl(llvm::detail::PassConcept>&, llvm::Function&, llvm::AnalysisManager&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:128:5
#38 0x0000556dfe8382dd llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/IR/PassManager.cpp:132:23
#39 0x0000556dfc4e887d llvm::detail::PassModel>::runImpl(llvm::detail::PassConcept>&, llvm::Module&, llvm::AnalysisManager&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:128:5
#40 0x0000556dfe83383b llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:80:8
#41 0x0000556dff1e2efb llvm::SmallPtrSetImplBase::isSmall() const /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:244:33
#42 0x0000556dff1e2efb llvm::SmallPtrSetImplBase::~SmallPtrSetImplBase() /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:91:10
#43 0x0000556dff1e2efb llvm::PreservedAnalyses::~PreservedAnalyses() /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/IR/Analysis.h:112:7
#44 0x0000556dff1e2efb (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr>&, std::unique_ptr>&, clang::BackendConsumer*) /data/x27zhou/compiler-nightly/src/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1198:5
#45 0x0000556dff1d9a75 (anonymous namespace)::EmitAssemblyHelper::emitAssembly(clang::BackendAction, std::unique_ptr>, clang::BackendConsumer*) /data/x27zhou/compiler-nightly/src/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1259:23
#46 0x0000556dff1d7a38 std::unique_ptr>::~unique_ptr() /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/unique_ptr.h:395:12
#47 0x0000556dff1d7a38 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr, std::unique_ptr>, clang::BackendConsumer*) /data/x27zhou/compiler-nightly/src/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1555:3
#48 0x0000556dff792193 std::unique_ptr>::~unique_ptr() /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/unique_ptr.h:395:6
#49 0x0000556dff792193 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /data/x27zhou/compiler-nightly/src/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:322:3
#50 0x0000556e00e013a7 clang::ParseAST(clang::Sema&, bool, bool) /data/x27zhou/compiler-nightly/src/llvm-project/clang/lib/Parse/ParseAST.cpp:0:13
#51 0x0000556dffa1a226 clang::FrontendAction::Execute() /data/x27zhou/compiler-nightly/src/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1373:10
#52 0x0000556dff995bb8 llvm::Error::getPtr() const /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/Support/Error.h:278:42
#53 0x0000556dff995bb8 llvm::Error::operator bool() /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/Support/Error.h:241:16
#54 0x0000556dff995bb8 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /data/x27zhou/compiler-nightly/src/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1040:23
#55 0x0000556dffad1f15 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /data/x27zhou/compiler-nightly/src/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:332:25
#56 0x0000556dfc053956 cc1_main(llvm::ArrayRef, char const*, void*) /data/x27zhou/compiler-nightly/src/llvm-project/clang/tools/driver/cc1_main.cpp:296:13
#57 0x0000556dfc04fe04 ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) /data/x27zhou/compiler-nightly/src/llvm-project/clang/tools/driver/driver.cpp:229:12
#58 0x0000556dfc04ef03 clang_main(int, char**, llvm::ToolContext const&) /data/x27zhou/compiler-nightly/src/llvm-project/clang/tools/driver/driver.cpp:277:12
#59 0x0000556dfc05edad main /data/x27zhou/compiler-nightly/build/llvm/tools/clang/tools/driver/clang-driver.cpp:17:10
#60 0x00007fd5d96b6d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#61 0x00007fd5d96b6e40 call_init ./csu/../csu/libc-start.c:128:20
#62 0x00007fd5d96b6e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#63 0x0000556dfc04d6f5 _start (/data/x27zhou/compiler-nightly/install/llvm/bin/clang-24+0xec46f5)
clang: error: unable to execute command: Segmentation fault (core dumped)
clang: error: clang frontend command failed with exit code -2 (use -v to see invocation)
clang version 24.0.0git (https://github.com/llvm/llvm-project.git 25728f8e380096df53f3aa966068ec3a24271b30)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /data/x27zhou/compiler-nightly/install/llvm/bin
Build config: +assertions
clang: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING CRASH REPRODUCER FILES TO THE BUG REPORT:
clang: note: diagnostic msg: /tmp/small-d24fba.c
clang: note: diagnostic msg: /tmp/small-d24fba.sh
clang: note: diagnostic msg:
********************
```
Contributor guide
Research direction
Start by reproducing the crash with clang-trunk -O2 small.c and inspect the VPlanValue.h, VPlanRecipes.cpp, VPlanUtils.cpp, and VPlanTransforms.cpp paths shown in the stack trace. Trace the loop-vectorization path from LoopVectorize.cpp through removeDeadRecipes; done means the provided small.c no longer crashes and regression coverage verifies the failure case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100