llvm-project
llvm-project copied to clipboard
clang crashes on valid code at -O2 and above "Assertion `UnscheduledDeps >= 0 && "Expected valid number of unscheduled deps"' failed."
Hi,
Here is a crash I found.
small.c
#include <stdint.h>
# define CHAR_BIT 8
#define safe_mod_func_int8_t_s_s(_si1,_si2) \
({ int8_t si1 = (_si1); int8_t si2 = (_si2) ; \
((((int8_t)(si2)) == ((int8_t)0)) || ((((int8_t)(si1)) == (INT8_MIN)) && (((int8_t)(si2)) == ((int8_t)-1)))) \
? ((int8_t)(si1)) \
: (((int8_t)(si1)) % ((int8_t)(si2)));})
#define safe_sub_func_int32_t_s_s(_si1,_si2) \
({ int32_t si1 = (_si1); int32_t si2 = (_si2) ; \
(((((int32_t)(si1))^((int32_t)(si2))) \
& (((((int32_t)(si1)) ^ ((((int32_t)(si1))^((int32_t)(si2))) \
& (((int32_t)1) << (sizeof(int32_t)*CHAR_BIT-1))))-((int32_t)(si2)))^((int32_t)(si2)))) < ((int32_t)0)) \
? ((int32_t)(si1)) \
: (((int32_t)(si1)) - ((int32_t)(si2))) \
;})
#define safe_add_func_uint64_t_u_u(_ui1,_ui2) \
({ uint64_t ui1 = (_ui1); uint64_t ui2 = (_ui2) ; \
((uint64_t)(ui1)) + ((uint64_t)(ui2));})
int32_t a, e;
int32_t *b, *d;
uint64_t ***c;
uint16_t **f;
static int32_t *g(int32_t);
static uint32_t h() {
int32_t *n[3];
int i;
for (i = 0; i < 3; i++)
n[i] = &e;
g(b == n[1]);
}
int32_t *g(int32_t j) {
int32_t k = -3L;
uint64_t l[3];
int32_t *m = &a;
*m = j & safe_sub_func_int32_t_s_s(
safe_mod_func_int8_t_s_s(
d == (**f = safe_sub_func_int32_t_s_s(
-1L, safe_add_func_uint64_t_u_u(5, ***c)),
l) ^
k,
j),
k);
}
int main() { h(); }
$clang-trunk -O2 -w small.c
clang-21: /home/haoxin/research/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:4403: int llvm::slpvectorizer::BoUpSLP::ScheduleData::incrementUnscheduledDeps(int): Assertion `UnscheduledDeps >= 0 && "Expected valid number of unscheduled deps"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /home/haoxin/research/llvm-project/build/bin/clang-21 -cc1 -triple x86_64-unknown-linux-gnu -Os -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/haoxin/test-env/reduce-test -fcoverage-compilation-dir=/home/haoxin/test-env/reduce-test -resource-dir /home/haoxin/research/llvm-project/build/lib/clang/24 -c-isystem /home/haoxin/github/se2ct/csmith-marker/include/csmith-2.3.0/ -internal-isystem /home/haoxin/research/llvm-project/build/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 -w -ferror-limit 19 -fmessage-length=218 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -vectorize-loops -vectorize-slp -faddrsig -fdwarf2-cfi-asm -o /tmp/small-939abd.o -x c small.c
1. <eof> parser at end of file
2. Optimizer
3. Running pass "function<eager-inv>(drop-unnecessary-assumes,float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto;check-exit-count>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,drop-unnecessary-assumes<drop-deref>,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-arithmetic;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;aggregate-to-vector>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,mergeicmps,expand-memcmp,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;switch-to-arithmetic;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 "small.c"
4. Running pass "slp-vectorizer" on function "main"
#0 0x00005634f5d7cab9 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/haoxin/research/llvm-project/build/bin/clang-21+0x4529ab9)
#1 0x00005634f5d7977c llvm::sys::RunSignalHandlers() (/home/haoxin/research/llvm-project/build/bin/clang-21+0x452677c)
#2 0x00005634f5d798e6 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00005634f5d799ac SignalHandlerTerminate(int, siginfo_t*, void*) Signals.cpp:0:0
#4 0x00007f4a9c242520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#5 0x00007f4a9c2969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#6 0x00007f4a9c2969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#7 0x00007f4a9c2969fc pthread_kill ./nptl/pthread_kill.c:89:10
#8 0x00007f4a9c242476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#9 0x00007f4a9c2287f3 abort ./stdlib/abort.c:81:7
#10 0x00007f4a9c22871b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#11 0x00007f4a9c239e96 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#12 0x00005634f7b50918 auto void llvm::slpvectorizer::BoUpSLP::BlockScheduling::schedule<llvm::SetVector<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, llvm::SmallVector<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, 0u>, llvm::DenseSet<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, llvm::DenseMapInfo<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, void>>, 0u>>(llvm::slpvectorizer::BoUpSLP const&, llvm::slpvectorizer::InstructionsState const&, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&, llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, llvm::SetVector<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, llvm::SmallVector<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, 0u>, llvm::DenseSet<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, llvm::DenseMapInfo<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, void>>, 0u>&)::'lambda'(llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, llvm::ArrayRef<llvm::slpvectorizer::BoUpSLP::ScheduleBundle*>)::operator()(llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, llvm::ArrayRef<llvm::slpvectorizer::BoUpSLP::ScheduleBundle*>) const::'lambda'(llvm::SetVector<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, llvm::SmallVector<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, 0u>, llvm::DenseSet<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, llvm::DenseMapInfo<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, void>>, 0u>*, bool)::operator()<llvm::slpvectorizer::BoUpSLP::ScheduleData>(llvm::SetVector<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, llvm::SmallVector<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, 0u>, llvm::DenseSet<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, llvm::DenseMapInfo<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, void>>, 0u>*, bool) const (/home/haoxin/research/llvm-project/build/bin/clang-21+0x62fd918)
#13 0x00005634f7b566dd void llvm::slpvectorizer::BoUpSLP::BlockScheduling::schedule<llvm::SetVector<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, llvm::SmallVector<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, 0u>, llvm::DenseSet<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, llvm::DenseMapInfo<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, void>>, 0u>>(llvm::slpvectorizer::BoUpSLP const&, llvm::slpvectorizer::InstructionsState const&, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&, llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, llvm::SetVector<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, llvm::SmallVector<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, 0u>, llvm::DenseSet<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, llvm::DenseMapInfo<llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, void>>, 0u>&)::'lambda'(llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, llvm::ArrayRef<llvm::slpvectorizer::BoUpSLP::ScheduleBundle*>)::operator()(llvm::slpvectorizer::BoUpSLP::ScheduleEntity*, llvm::ArrayRef<llvm::slpvectorizer::BoUpSLP::ScheduleBundle*>) const (/home/haoxin/research/llvm-project/build/bin/clang-21+0x63036dd)
#14 0x00005634f7b57c16 llvm::slpvectorizer::BoUpSLP::BlockScheduling::tryScheduleBundle(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP*, llvm::slpvectorizer::InstructionsState const&, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&)::'lambda10'(bool, llvm::slpvectorizer::BoUpSLP::ScheduleBundle&)::operator()(bool, llvm::slpvectorizer::BoUpSLP::ScheduleBundle&) const SLPVectorizer.cpp:0:0
#15 0x00005634f7b5a90b llvm::slpvectorizer::BoUpSLP::BlockScheduling::tryScheduleBundle(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP*, llvm::slpvectorizer::InstructionsState const&, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/home/haoxin/research/llvm-project/build/bin/clang-21+0x630790b)
#16 0x00005634f7b5c99e llvm::slpvectorizer::BoUpSLP::buildTreeRec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&, unsigned int) (/home/haoxin/research/llvm-project/build/bin/clang-21+0x630999e)
#17 0x00005634f7b5fc3f llvm::slpvectorizer::BoUpSLP::buildTreeRec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&, unsigned int) (/home/haoxin/research/llvm-project/build/bin/clang-21+0x630cc3f)
#18 0x00005634f7b60d19 llvm::slpvectorizer::BoUpSLP::buildTreeRec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&, unsigned int) (/home/haoxin/research/llvm-project/build/bin/clang-21+0x630dd19)
#19 0x00005634f7b8cf5c llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool, bool) (.constprop.0) SLPVectorizer.cpp:0:0
#20 0x00005634f7b92b9a bool llvm::SLPVectorizerPass::vectorizeCmpInsts<std::reverse_iterator<llvm::CmpInst* const*>>(llvm::iterator_range<std::reverse_iterator<llvm::CmpInst* const*>>, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallSetVector<llvm::Instruction*, 8u>&) (/home/haoxin/research/llvm-project/build/bin/clang-21+0x633fb9a)
#21 0x00005634f7b93482 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&)::'lambda3'(bool)::operator()(bool) const SLPVectorizer.cpp:0:0
#22 0x00005634f7b9644d llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/home/haoxin/research/llvm-project/build/bin/clang-21+0x634344d)
#23 0x00005634f7b9709c llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0
#24 0x00005634f7b97cfe llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/haoxin/research/llvm-project/build/bin/clang-21+0x6344cfe)
#25 0x00005634f70312b6 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::runImpl(llvm::detail::PassConcept<llvm::Function, llvm::AnalysisManager<llvm::Function>>&, llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/haoxin/research/llvm-project/build/bin/clang-21+0x57de2b6)
#26 0x00005634f5679f84 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/haoxin/research/llvm-project/build/bin/clang-21+0x3e26f84)
#27 0x00005634f2b7a686 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::runImpl(llvm::detail::PassConcept<llvm::Function, llvm::AnalysisManager<llvm::Function>>&, llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/haoxin/research/llvm-project/build/bin/clang-21+0x1327686)
#28 0x00005634f56780f7 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/haoxin/research/llvm-project/build/bin/clang-21+0x3e250f7)
#29 0x00005634f2b7a7e6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::runImpl(llvm::detail::PassConcept<llvm::Module, llvm::AnalysisManager<llvm::Module>>&, llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/haoxin/research/llvm-project/build/bin/clang-21+0x13277e6)
#30 0x00005634f5678af4 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/haoxin/research/llvm-project/build/bin/clang-21+0x3e25af4)
#31 0x00005634f61b496e (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
#32 0x00005634f61b6d7e (anonymous namespace)::EmitAssemblyHelper::emitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) BackendUtil.cpp:0:0
#33 0x00005634f61b9498 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*) (/home/haoxin/research/llvm-project/build/bin/clang-21+0x4966498)
#34 0x00005634f68a611a clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/haoxin/research/llvm-project/build/bin/clang-21+0x505311a)
#35 0x00005634f840f175 clang::ParseAST(clang::Sema&, bool, bool) (/home/haoxin/research/llvm-project/build/bin/clang-21+0x6bbc175)
#36 0x00005634f6c02c91 clang::FrontendAction::Execute() (/home/haoxin/research/llvm-project/build/bin/clang-21+0x53afc91)
#37 0x00005634f6b8b9f5 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/haoxin/research/llvm-project/build/bin/clang-21+0x53389f5)
#38 0x00005634f6cdb5e3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/haoxin/research/llvm-project/build/bin/clang-21+0x54885e3)
#39 0x00005634f26684e6 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/haoxin/research/llvm-project/build/bin/clang-21+0xe154e6)
#40 0x00005634f265dfea ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#41 0x00005634f2662455 clang_main(int, char**, llvm::ToolContext const&) (/home/haoxin/research/llvm-project/build/bin/clang-21+0xe0f455)
#42 0x00005634f257d411 main (/home/haoxin/research/llvm-project/build/bin/clang-21+0xd2a411)
#43 0x00007f4a9c229d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#44 0x00007f4a9c229e40 call_init ./csu/../csu/libc-start.c:128:20
#45 0x00007f4a9c229e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#46 0x00005634f265d615 _start (/home/haoxin/research/llvm-project/build/bin/clang-21+0xe0a615)
clang: error: unable to execute command: Aborted
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 1a176af243e78fad48ce0d6ecd1311c1e9f943d8)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/haoxin/research/llvm-project/build/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-6c6bd8.c
clang: note: diagnostic msg: /tmp/small-6c6bd8.sh
clang: note: diagnostic msg:
********************
Aborted
$clang-trunk -v
clang-trunk version 24.0.0git (https://github.com/llvm/llvm-project.git 1a176af243e78fad48ce0d6ecd1311c1e9f943d8)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/haoxin/research/llvm-project/build/bin
Build config: +assertions
Found candidate GCC installation: /usr/lib/gcc-cross/i686-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc-cross/x86_64-linux-gnux32/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@m64
Selected multilib: .;@m64
Found CUDA installation: /usr/local/cuda, version 13.1
Thanks.
i'd like to work on this
@haoxintu this issue looks like it already fixed in the latest version of LLVM. https://godbolt.org/z/dsGve5T4q let me know if im wrong any where...
Looks like it was already fixed by f6645af15a34
yeah