Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang crashes on valid code at -Os and above: Assertion `!empty()' failed (SLP vectorizer) #50619

Closed
zhendongsu opened this issue Jul 29, 2021 · 5 comments
Labels
bugzilla Issues migrated from bugzilla

Comments

@zhendongsu
Copy link

Bugzilla Link 51275
Resolution FIXED
Resolved on Jul 30, 2021 07:49
Version trunk
OS All
CC @alexey-bataev,@RKSimon,@rotateright
Fixed by commit(s) c2deb2a

Extended Description

It appears to be a recent regression.

[633] % clangtk -v
clang version 14.0.0 (https://github.com/llvm/llvm-project.git 26be7fe)
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::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. 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::ArrayRefllvm::Value*) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x3c03306)
    #​8 0x000055821875b1e2 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRefllvm::Value*) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x3c1e1e2)
    #​9 0x000055821875d111 llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRefllvm::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::AnalysisManagerllvm::Function&) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x3c299cb)
    #​13 0x00005582196c4b41 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::PreservedAnalyses, llvm::AnalysisManagerllvm::Function >::run(llvm::Function&, llvm::AnalysisManagerllvm::Function&) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x4b87b41)
    #​14 0x0000558217cd2f2c llvm::PassManager<llvm::Function, llvm::AnalysisManagerllvm::Function >::run(llvm::Function&, llvm::AnalysisManagerllvm::Function&) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x3195f2c)
    #​15 0x00005582162a8cf1 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManagerllvm::Function >, llvm::PreservedAnalyses, llvm::AnalysisManagerllvm::Function >::run(llvm::Function&, llvm::AnalysisManagerllvm::Function&) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x176bcf1)
    #​16 0x0000558217cd2814 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManagerllvm::Module&) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x3195814)
    #​17 0x00005582162a96f1 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManagerllvm::Module >::run(llvm::Module&, llvm::AnalysisManagerllvm::Module&) (/local/suz-local/software/local/clang-trunk/bin/clang-14+0x176c6f1)
    #​18 0x0000558217cd0fd4 llvm::PassManager<llvm::Module, llvm::AnalysisManagerllvm::Module >::run(llvm::Module&, llvm::AnalysisManagerllvm::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_deletellvm::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_deletellvm::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 26be7fe)
    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;
}

@rotateright
Copy link
Contributor

This was noted by someone else just a bit earlier.
Patch review underway here:
https://reviews.llvm.org/D107058

@rotateright
Copy link
Contributor

For reference, the bug was probably uncovered by this patch:
https://reviews.llvm.org/D105020 / https://reviews.llvm.org/rGe408d1dfab42b27d0aa51b221

@zhendongsu
Copy link
Author

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!

@rotateright
Copy link
Contributor

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.

@zhendongsu
Copy link
Author

I checked all the triggering tests I have; all good. Thanks, Sanjay!

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

2 participants