llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.1k stars 12.01k forks source link

clang crashes on valid code at -Os and above: Assertion `idx < size()' failed #36693

Closed zhendongsu closed 3 years ago

zhendongsu commented 6 years ago
Bugzilla Link 37345
Resolution WORKSFORME
Resolved on Feb 20, 2021 14:10
Version unspecified
OS All
CC @nikic

Extended Description

Tested with trunk revision 331481.

$ clangpolly -v clang version 7.0.0 (http://llvm.org/git/clang.git 448ee95831d1eca7143e7639718584faba754da2) (llvm/trunk 331481) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /home/su/bin Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9 Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9.4 Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/5 Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/5.3.0 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4.7 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6.4 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7.3 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.5 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.4 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.3.0 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.2.0 Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Candidate multilib: x32;@mx32 Selected multilib: .;@m64 $ $ clangpolly -O1 -c -w small.c $ $ clangpolly -Os -c -w small.c clang-6.0: /home/su/software/tmp/polly/llvm/include/llvm/ADT/SmallVector.h:149: T& llvm::SmallVectorTemplateCommon<T, >::operator[](llvm::SmallVectorTemplateCommon<T, >::size_type) [with T = llvm::Value; = void; llvm::SmallVectorTemplateCommon<T, >::reference = llvm::Value&; llvm::SmallVectorTemplateCommon<T, >::size_type = long unsigned int]: Assertion `idx < size()' failed. Stack dump:

  1. Program arguments: /home/su/software/tmp/polly/llvm_build/bin/clang-6.0 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free -main-file-name small.c -mrelocation-model static -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -coverage-notes-file /home/su/specres/good/20180501-clangpolly-m32-O3-Wall-Wextra-pedantic-std=c99-build-204641/small.gcno -resource-dir /home/su/software/tmp/polly/llvm_build/lib/clang/7.0.0 -internal-isystem /usr/local/include -internal-isystem /home/su/software/tmp/polly/llvm_build/lib/clang/7.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Os -w -fdebug-compilation-dir /home/su/specres/good/20180501-clangpolly-m32-O3-Wall-Wextra-pedantic-std=c99-build-204641 -ferror-limit 19 -fmessage-length 116 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o small.o -x c small.c
  2. parser at end of file
  3. Per-module optimization passes
  4. Running pass 'CallGraph Pass Manager' on module 'small.c'.
  5. Running pass 'Jump Threading' on function '@m'

    ​0 0x00000000025414da llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/su/software/tmp/polly/llvm/lib/Support/Unix/Signals.inc:403:0

    ​1 0x000000000253f68e llvm::sys::RunSignalHandlers() /home/su/software/tmp/polly/llvm/lib/Support/Signals.cpp:50:0

    ​2 0x000000000253f7f0 SignalHandler(int) /home/su/software/tmp/polly/llvm/lib/Support/Unix/Signals.inc:243:0

    ​3 0x00007fdc46513330 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)

    ​4 0x00007fdc452fbc37 gsignal /build/eglibc-SvCtMH/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0

    ​5 0x00007fdc452ff028 abort /build/eglibc-SvCtMH/eglibc-2.19/stdlib/abort.c:91:0

    ​6 0x00007fdc452f4bf6 __assert_fail_base /build/eglibc-SvCtMH/eglibc-2.19/assert/assert.c:92:0

    ​7 0x00007fdc452f4ca2 (/lib/x86_64-linux-gnu/libc.so.6+0x2fca2)

    ​8 0x0000000001af01e0 llvm::isa_impl_cl<llvm::ConstantInt, llvm::Value const>::doit(llvm::Value const) /home/su/software/tmp/polly/llvm/include/llvm/ADT/SmallVector.h:149:0

    ​9 0x0000000001af01e0 llvm::isa_impl_wrap<llvm::ConstantInt, llvm::Value const, llvm::Value const>::doit(llvm::Value const* const&) /home/su/software/tmp/polly/llvm/include/llvm/Support/Casting.h:133:0

    ​10 0x0000000001af01e0 llvm::isa_impl_wrap<llvm::ConstantInt, llvm::Use const, llvm::Value const>::doit(llvm::Use* const&) /home/su/software/tmp/polly/llvm/include/llvm/Support/Casting.h:125:0

    ​11 0x0000000001af01e0 isa<llvm::ConstantInt, llvm::Use*> /home/su/software/tmp/polly/llvm/include/llvm/Support/Casting.h:144:0

    ​12 0x0000000001af01e0 llvm::BasicAAResult::aliasPHI(llvm::PHINode const, unsigned long, llvm::AAMDNodes const&, llvm::Value const, unsigned long, llvm::AAMDNodes const&, llvm::Value const*) /home/su/software/tmp/polly/llvm/lib/Analysis/BasicAliasAnalysis.cpp:1529:0

    ​13 0x0000000001aeda28 llvm::BasicAAResult::aliasCheck(llvm::Value const, unsigned long, llvm::AAMDNodes, llvm::Value const, unsigned long, llvm::AAMDNodes, llvm::Value const, llvm::Value const) /home/su/software/tmp/polly/llvm/lib/Analysis/BasicAliasAnalysis.cpp:1691:0

    ​14 0x0000000001aef0b2 llvm::SmallDenseMap<std::pair<llvm::MemoryLocation, llvm::MemoryLocation>, llvm::AliasResult, 8u, llvm::DenseMapInfo<std::pair<llvm::MemoryLocation, llvm::MemoryLocation> >, llvm::detail::DenseMapPair<std::pair<llvm::MemoryLocation, llvm::MemoryLocation>, llvm::AliasResult> >::getNumBuckets() const /home/su/software/tmp/polly/llvm/include/llvm/ADT/DenseMap.h:1086:0

    ​15 0x0000000001aef0b2 llvm::DenseMapBase<llvm::SmallDenseMap<std::pair<llvm::MemoryLocation, llvm::MemoryLocation>, llvm::AliasResult, 8u, llvm::DenseMapInfo<std::pair<llvm::MemoryLocation, llvm::MemoryLocation> >, llvm::detail::DenseMapPair<std::pair<llvm::MemoryLocation, llvm::MemoryLocation>, llvm::AliasResult> >, std::pair<llvm::MemoryLocation, llvm::MemoryLocation>, llvm::AliasResult, llvm::DenseMapInfo<std::pair<llvm::MemoryLocation, llvm::MemoryLocation> >, llvm::detail::DenseMapPair<std::pair<llvm::MemoryLocation, llvm::MemoryLocation>, llvm::AliasResult> >::getNumBuckets() const /home/su/software/tmp/polly/llvm/include/llvm/ADT/DenseMap.h:490:0

    ​16 0x0000000001aef0b2 llvm::DenseMapBase<llvm::SmallDenseMap<std::pair<llvm::MemoryLocation, llvm::MemoryLocation>, llvm::AliasResult, 8u, llvm::DenseMapInfo<std::pair<llvm::MemoryLocation, llvm::MemoryLocation> >, llvm::detail::DenseMapPair<std::pair<llvm::MemoryLocation, llvm::MemoryLocation>, llvm::AliasResult> >, std::pair<llvm::MemoryLocation, llvm::MemoryLocation>, llvm::AliasResult, llvm::DenseMapInfo<std::pair<llvm::MemoryLocation, llvm::MemoryLocation> >, llvm::detail::DenseMapPair<std::pair<llvm::MemoryLocation, llvm::MemoryLocation>, llvm::AliasResult> >::destroyAll() /home/su/software/tmp/polly/llvm/include/llvm/ADT/DenseMap.h:327:0

    ​17 0x0000000001aef0b2 llvm::SmallDenseMap<std::pair<llvm::MemoryLocation, llvm::MemoryLocation>, llvm::AliasResult, 8u, llvm::DenseMapInfo<std::pair<llvm::MemoryLocation, llvm::MemoryLocation> >, llvm::detail::DenseMapPair<std::pair<llvm::MemoryLocation, llvm::MemoryLocation>, llvm::AliasResult> >::shrink_and_clear() /home/su/software/tmp/polly/llvm/include/llvm/ADT/DenseMap.h:1014:0

    ​18 0x0000000001aef0b2 llvm::BasicAAResult::alias(llvm::MemoryLocation const&, llvm::MemoryLocation const&) /home/su/software/tmp/polly/llvm/lib/Analysis/BasicAliasAnalysis.cpp:767:0

    ​19 0x0000000001acec98 llvm::AAResults::alias(llvm::MemoryLocation const&, llvm::MemoryLocation const&) /home/su/software/tmp/polly/llvm/lib/Analysis/AliasAnalysis.cpp:106:0

    ​20 0x0000000001acf49d llvm::AAResults::getModRefInfo(llvm::StoreInst const*, llvm::MemoryLocation const&) /home/su/software/tmp/polly/llvm/lib/Analysis/AliasAnalysis.cpp:408:0

    ​21 0x0000000001b9f81d llvm::FindAvailablePtrLoadStore(llvm::Value, llvm::Type, bool, llvm::BasicBlock, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, false>&, unsigned int, llvm::AAResults, bool, unsigned int) /home/su/software/tmp/polly/llvm/lib/Analysis/Loads.cpp:417:0

    ​22 0x0000000001b9ff6e llvm::FindAvailableLoadedValue(llvm::LoadInst, llvm::BasicBlock, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, false>&, unsigned int, llvm::AAResults, bool, unsigned int*) /home/su/software/tmp/polly/llvm/lib/Analysis/Loads.cpp:334:0

    ​23 0x0000000002393da8 llvm::JumpThreadingPass::SimplifyPartiallyRedundantLoad(llvm::LoadInst*) (.part.817) /home/su/software/tmp/polly/llvm/lib/Transforms/Scalar/JumpThreading.cpp:1290:0

    ​24 0x0000000002399c29 llvm::JumpThreadingPass::ProcessBlock(llvm::BasicBlock*) /home/su/software/tmp/polly/llvm/lib/Transforms/Scalar/JumpThreading.cpp:1180:0

    ​25 0x000000000239a4e1 llvm::JumpThreadingPass::runImpl(llvm::Function&, llvm::TargetLibraryInfo, llvm::LazyValueInfo, llvm::AAResults, llvm::DeferredDominance, bool, std::unique_ptr<llvm::BlockFrequencyInfo, std::default_delete >, std::unique_ptr<llvm::BranchProbabilityInfo, std::default_delete >) /home/su/software/tmp/polly/llvm/lib/Transforms/Scalar/JumpThreading.cpp:377:0

    ​26 0x000000000239ab6a ~unique_ptr /usr/include/c++/4.9/bits/unique_ptr.h:235:0

    ​27 0x000000000239ab6a (anonymous namespace)::JumpThreading::runOnFunction(llvm::Function&) (.part.868) /home/su/software/tmp/polly/llvm/lib/Transforms/Scalar/JumpThreading.cpp:299:0

    ​28 0x000000000208ca2b llvm::FPPassManager::runOnFunction(llvm::Function&) /home/su/software/tmp/polly/llvm/lib/IR/LegacyPassManager.cpp:1520:0

    ​29 0x0000000001b2cd66 RunPassOnSCC /home/su/software/tmp/polly/llvm/lib/Analysis/CallGraphSCCPass.cpp:156:0

    ​30 0x0000000001b2cd66 RunAllPassesOnSCC /home/su/software/tmp/polly/llvm/lib/Analysis/CallGraphSCCPass.cpp:424:0

    ​31 0x0000000001b2cd66 (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) /home/su/software/tmp/polly/llvm/lib/Analysis/CallGraphSCCPass.cpp:479:0

    ​32 0x000000000208d73a runOnModule /home/su/software/tmp/polly/llvm/lib/IR/LegacyPassManager.cpp:1597:0

    ​33 0x000000000208d73a llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/su/software/tmp/polly/llvm/lib/IR/LegacyPassManager.cpp:1700:0

    ​34 0x00000000026f64dd ~PrettyStackTraceString /home/su/software/tmp/polly/llvm/include/llvm/Support/PrettyStackTrace.h:52:0

    ​35 0x00000000026f64dd (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete >) /home/su/software/tmp/polly/llvm/tools/clang/lib/CodeGen/BackendUtil.cpp:815:0

    ​36 0x00000000026f79b4 ~unique_ptr /usr/include/c++/4.9/bits/unique_ptr.h:235:0

    ​37 0x00000000026f79b4 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete >) /home/su/software/tmp/polly/llvm/tools/clang/lib/CodeGen/BackendUtil.cpp:1220:0

    ​38 0x0000000002f54fac ~unique_ptr /usr/include/c++/4.9/bits/unique_ptr.h:235:0

    ​39 0x0000000002f54fac clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /home/su/software/tmp/polly/llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:294:0

    ​40 0x00000000034771cc clang::ParseAST(clang::Sema&, bool, bool) /home/su/software/tmp/polly/llvm/tools/clang/lib/Parse/ParseAST.cpp:164:0

    ​41 0x0000000002f54440 clang::CodeGenAction::ExecuteAction() /home/su/software/tmp/polly/llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:1044:0

    ​42 0x0000000002afde46 clang::FrontendAction::Execute() /home/su/software/tmp/polly/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:904:0

    ​43 0x0000000002ad0436 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/su/software/tmp/polly/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:990:0

    ​44 0x0000000002b96da1 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/su/software/tmp/polly/llvm/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:255:0

    ​45 0x0000000000e046d0 cc1_main(llvm::ArrayRef<char const>, char const, void*) /home/su/software/tmp/polly/llvm/tools/clang/tools/driver/cc1_main.cpp:222:0

    ​46 0x0000000000d878c1 ExecuteCC1Tool /home/su/software/tmp/polly/llvm/tools/clang/tools/driver/driver.cpp:310:0

    ​47 0x0000000000d878c1 main /home/su/software/tmp/polly/llvm/tools/clang/tools/driver/driver.cpp:382:0

    ​48 0x00007fdc452e6f45 __libc_start_main /build/eglibc-SvCtMH/eglibc-2.19/csu/libc-start.c:321:0

    ​49 0x0000000000e004c9 _start (/home/su/software/tmp/polly/llvm_build/bin/clang-6.0+0xe004c9)

    clang-6.0: error: unable to execute command: Aborted (core dumped) clang-6.0: error: clang frontend command failed due to signal (use -v to see invocation) clang version 7.0.0 (http://llvm.org/git/clang.git 448ee95831d1eca7143e7639718584faba754da2) (llvm/trunk 331481) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /home/su/bin clang-6.0: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script. clang-6.0: note: diagnostic msg:


PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang-6.0: note: diagnostic msg: /tmp/small-6d96aa.c clang-6.0: note: diagnostic msg: /tmp/small-6d96aa.sh clang-6.0: note: diagnostic msg:


$


char a, b, c, d; int e, f, g, h, i, j, *k;

char l () { return c ? c : b % c; }

int m () { char n[1]; int o; n[0] = 1; while (a) { if (n[0]) continue; int p, q = &p; while (h) { short r; if (d) { int s = &o; s = &i; return 0; } p = 0; j = e ? e : 3 / e; k = j; if (p) continue; return 0; } if (n[g]) { int s = &o; o = l (); s = q; } if (f) continue; o ? 0 : f && a; return 1; } return 0; }

nikic commented 3 years ago

Doesn't reproduce on current trunk, so either the issue was fixed in the meantime, or other changes have hidden the issue for this reproducer.