LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 51275 - clang crashes on valid code at -Os and above: Assertion `!empty()' failed (SLP vectorizer)
Summary: clang crashes on valid code at -Os and above: Assertion `!empty()' failed (SL...
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Scalar Optimizations (show other bugs)
Version: trunk
Hardware: PC All
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-07-29 14:26 PDT by Zhendong Su
Modified: 2021-07-30 07:49 PDT (History)
5 users (show)

See Also:
Fixed By Commit(s): c2deb2afafee991c06cc9


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zhendong Su 2021-07-29 14:26:46 PDT
It appears to be a recent regression.

[633] % clangtk -v
clang version 14.0.0 (https://github.com/llvm/llvm-project.git 26be7fe27c66a4db21ca2290ade10b171513177f)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /local/suz-local/opfuzz/bin
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Candidate multilib: .;@m64
Selected multilib: .;@m64
[634] % 
[634] % clangtk -O1 small.c
[635] % 
[635] % clangtk -Os small.c
clang-14: /local/suz-local/software/clangbuild/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:169: const T& llvm::ArrayRef<T>::front() const [with T = llvm::Value*]: Assertion `!empty()' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /local/suz-local/software/local/clang-trunk/bin/clang-14 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj --mrelax-relocations -disable-free -main-file-name small.c -mrelocation-model static -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/suz -resource-dir /local/suz-local/software/local/clang-trunk/lib/clang/14.0.0 -I /usr/local/include/csmith -I /local/suz-local/software/local/include -internal-isystem /local/suz-local/software/local/clang-trunk/lib/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Os -fdebug-compilation-dir=/home/suz -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-374d0a.o -x c small.c
1.	<eof> parser at end of file
2.	Optimizer
 #0 0x0000558218505c4f PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x00005582185033fd SignalHandler(int) Signals.cpp:0:0
 #2 0x00007ff0f83bb8a0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x128a0)
 #3 0x00007ff0f706cf47 raise /build/glibc-2ORdQG/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #4 0x00007ff0f706e8b1 abort /build/glibc-2ORdQG/glibc-2.27/stdlib/abort.c:81:0
 #5 0x00007ff0f705e42a __assert_fail_base /build/glibc-2ORdQG/glibc-2.27/assert/assert.c:89:0
 #6 0x00007ff0f705e4a2 (/lib/x86_64-linux-gnu/libc.so.6+0x304a2)
 #7 0x0000558218740306 llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x3c03306)
 #8 0x000055821875b1e2 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x3c1e1e2)
 #9 0x000055821875d111 llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x3c20111)
#10 0x0000558218762b30 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x3c25b30)
#11 0x00005582187659bc llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.2032) SLPVectorizer.cpp:0:0
#12 0x00005582187669cb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x3c299cb)
#13 0x00005582196c4b41 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x4b87b41)
#14 0x0000558217cd2f2c llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x3195f2c)
#15 0x00005582162a8cf1 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x176bcf1)
#16 0x0000558217cd2814 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x3195814)
#17 0x00005582162a96f1 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x176c6f1)
#18 0x0000558217cd0fd4 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x3193fd4)
#19 0x00005582188074b4 (anonymous namespace)::EmitAssemblyHelper::EmitAssemblyWithNewPassManager(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) BackendUtil.cpp:0:0
#20 0x000055821880c3f3 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x3ccf3f3)
#21 0x00005582194f6d4a clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x49b9d4a)
#22 0x000055821a3cf659 clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x5892659)
#23 0x00005582194f6ee8 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x49b9ee8)
#24 0x0000558218e440f1 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x43070f1)
#25 0x0000558218de03ca clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x42a33ca)
#26 0x0000558218f1374a clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x43d674a)
#27 0x000055821601768c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x14da68c)
#28 0x0000558216012a39 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#29 0x0000558215f406b6 main (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x14036b6)
#30 0x00007ff0f704fb97 __libc_start_main /build/glibc-2ORdQG/glibc-2.27/csu/../csu/libc-start.c:344:0
#31 0x00005582160125aa _start (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x14d55aa)
clang-14: error: unable to execute command: Aborted
clang-14: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 14.0.0 (https://github.com/llvm/llvm-project.git 26be7fe27c66a4db21ca2290ade10b171513177f)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /local/suz-local/opfuzz/bin
clang-14: note: diagnostic msg: 
********************

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

********************
[636] % 
[636] % cat small.c
int printf (const char *, ...);
int a, b;
#pragma pack(1)
struct {
  int c : 4;
  volatile int d : 9;
  int : 7;
  int e : 23;
  int f : 25;
} g, h, i, j;
volatile int k;
int main() {
  while (b) {
    g.d;
    int l = h.f ^ i.e ^ j.c;
    if (a)
      printf("%d", a);
    j.f = l;
    g.f && k;
  }
  return 0;
}
Comment 1 Sanjay Patel 2021-07-29 16:01:08 PDT
This was noted by someone else just a bit earlier. 
Patch review underway here:
https://reviews.llvm.org/D107058
Comment 2 Sanjay Patel 2021-07-29 16:07:36 PDT
For reference, the bug was probably uncovered by this patch:
https://reviews.llvm.org/D105020 / https://reviews.llvm.org/rGe408d1dfab42b27d0aa51b221
Comment 3 Zhendong Su 2021-07-30 03:27:14 PDT
> This was noted by someone else just a bit earlier. 

Okay, yes, this crash seems to be quite easy to trigger.

> Patch review underway here:
> https://reviews.llvm.org/D107058

Great; thanks, Sanjay!
Comment 4 Sanjay Patel 2021-07-30 05:59:56 PDT
Should be fixed with:
https://reviews.llvm.org/rGc2deb2afafee991c06cc9

I don't think the bug was visible in the 13.0 release, so I'm resolving as fixed. Please reopen if that's not correct.
Comment 5 Zhendong Su 2021-07-30 06:56:52 PDT
I checked all the triggering tests I have; all good.  Thanks, Sanjay!