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 at -O2 and -O3 in llvm/CodeGen/SelectionDAGNodes.h:959: llvm::EVT llvm::SDNode::getValueType(unsigned int) const: Assertion `ResNo < NumValues && "Illegal result number!"' failed #50954

Closed
haoxintu opened this issue Aug 25, 2021 · 4 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla llvm:codegen

Comments

@haoxintu
Copy link

Bugzilla Link 51612
Resolution FIXED
Resolved on Aug 25, 2021 14:11
Version trunk
OS Linux
CC @RKSimon,@rotateright
Fixed by commit(s) 985b48f 728d1a3e82b

Extended Description

Hi all.

$cat small.c
#include <stdint.h>
int a;
uint64_t b;
int c() {
uint64_t d = 0;
uint64_t *e = &d;
int16_t f = 0;
uint32_t g = 10;
uint32_t *i = g;
for (; b; b++)
a = ((d ?: b) & *i) >> (*e += 5 || f);
return 0;
}

$clang -w -m32 -O2 small.c
clang-14: /home/haoxin/haoxin-data/compilers/llvm-project/llvm/include/llvm/CodeGen/SelectionDAGNodes.h:959: llvm::EVT llvm::SDNode::getValueType(unsigned int) const: Assertion `ResNo < NumValues && "Illegal result number!"' 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: /home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14 -cc1 -triple i386-unknown-linux-gnu -emit-obj --mrelax-relocations -disable-free -main-file-name small.c -mrelocation-model static -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -target-cpu pentium4 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/haoxin/haoxin-data/dut-research/covsmith-test/20210819/8 -resource-dir /home/haoxin/haoxin-data/compilers/llvm-project/build/lib/clang/14.0.0 -internal-isystem /home/haoxin/haoxin-data/compilers/llvm-project/build/lib/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -w -fdebug-compilation-dir=/home/haoxin/haoxin-data/dut-research/covsmith-test/20210819/8 -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -o /tmp/small-8d5aa4.o -x c small.c

  1.  <eof> parser at end of file
    
  2.  Code generation
    
  3.  Running pass 'Function Pass Manager' on module 'small.c'.
    
  4.  Running pass 'X86 DAG->DAG Instruction Selection' on function '@c'
    

#​0 0x00005577ba629e24 PrintStackTraceSignalHandler(void*) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x3b26e24)
#​1 0x00005577ba62753e SignalHandler(int) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x3b2453e)
#​2 0x00007faf8d9bc3c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
#​3 0x00007faf8d45b18b raise /build/glibc-eX1tMB/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
#​4 0x00007faf8d43a859 abort /build/glibc-eX1tMB/glibc-2.31/stdlib/abort.c:81:7
#​5 0x00007faf8d43a729 get_sysdep_segment_value /build/glibc-eX1tMB/glibc-2.31/intl/loadmsgcat.c:509:8
#​6 0x00007faf8d43a729 _nl_load_domain /build/glibc-eX1tMB/glibc-2.31/intl/loadmsgcat.c:970:34
#​7 0x00007faf8d44bf36 (/lib/x86_64-linux-gnu/libc.so.6+0x36f36)
#​8 0x00005577bb4e9235 (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x49e6235)
#​9 0x00005577bb553be5 (anonymous namespace)::DAGCombiner::visitADDO(llvm::SDNode*) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x4a50be5)
#​10 0x00005577bb58c4cb (anonymous namespace)::DAGCombiner::visit(llvm::SDNode*) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x4a894cb)
#​11 0x00005577bb58ef45 (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x4a8bf45)
#​12 0x00005577bb590990 llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOpt::Level) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x4a8d990)
#​13 0x00005577bb698645 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (.localalias) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x4b95645)
#​14 0x00005577bb69c18b llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (.localalias) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x4b9918b)
#​15 0x00005577bb69e3a1 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (.part.0) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x4b9b3a1)
#​16 0x00005577b90a6e40 (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x25a3e40)
#​17 0x00005577b97e5568 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.localalias) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x2ce2568)
#​18 0x00005577b9cd7c35 llvm::FPPassManager::runOnFunction(llvm::Function&) (.localalias) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x31d4c35)
#​19 0x00005577b9cd7e79 llvm::FPPassManager::runOnModule(llvm::Module&) (.localalias) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x31d4e79)
#​20 0x00005577b9cd8f62 llvm::legacy::PassManagerImpl::run(llvm::Module&) (.localalias) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x31d5f62)
#​21 0x00005577ba96e94a (anonymous namespace)::EmitAssemblyHelper::EmitAssemblyWithNewPassManager(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_deletellvm::raw_pwrite_stream >) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x3e6b94a)
#​22 0x00005577ba97047d 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 >) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x3e6d47d)
#​23 0x00005577bb7d3d9f clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x4cd0d9f)
#​24 0x00005577bc53f3e9 clang::ParseAST(clang::Sema&, bool, bool) (.localalias) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x5a3c3e9)
#​25 0x00005577bb7d28e8 clang::CodeGenAction::ExecuteAction() (.localalias) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x4ccf8e8)
#​26 0x00005577bb067199 clang::FrontendAction::Execute() (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x4564199)
#​27 0x00005577baffc8ae clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (.localalias) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x44f98ae)
#​28 0x00005577bb145fb0 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x4642fb0)
#​29 0x00005577b7e3c2dd cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x13392dd)
#​30 0x00005577b7e38628 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x1335628)
#​31 0x00005577b7d6daa9 main (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x126aaa9)
#​32 0x00007faf8d43c0b3 __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:342:3
#​33 0x00005577b7e3819e _start (/home/haoxin/haoxin-data/compilers/llvm-project/build/bin/clang-14+0x133519e)
clang-14: error: unable to execute command: Aborted (core dumped)
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 c2574e6)
Target: i386-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/haoxin/haoxin-data/compilers/llvm-project/build/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-b5eb7c.c
clang-14: note: diagnostic msg: /tmp/small-b5eb7c.sh
clang-14: note: diagnostic msg:


Thanks,
Haoxin

@haoxintu
Copy link
Author

assigned to @rotateright

@RKSimon
Copy link
Collaborator

RKSimon commented Aug 25, 2021

Reduced:

@​a = external dso_local local_unnamed_addr global i32, align 4

define void @​c() {
entry:
br i1 undef, label %for.body.preheader14, label %vector.ph

vector.ph: ; preds = %entry
%n.vec = and i64 undef, -4
%ind.end = add i64 undef, %n.vec
br label %for.body.preheader14

for.body.preheader14: ; preds = %vector.ph, %entry
%d.010.ph = phi i64 [ 0, %entry ], [ %n.vec, %vector.ph ]
%.ph = phi i64 [ undef, %entry ], [ %ind.end, %vector.ph ]
%add = add i64 %d.010.ph, 1
%inc = add i64 %.ph, 1
%tobool1.not.1 = icmp eq i64 %add, 0
%cond.1 = select i1 %tobool1.not.1, i64 %inc, i64 %add
%i = load i32, i32* inttoptr (i32 10 to i32*), align 4
%conv.1 = zext i32 %i to i64
%and.1 = and i64 %cond.1, %conv.1
%shr.1 = lshr i64 %and.1, 0
%conv2.1 = trunc i64 %shr.1 to i32
store i32 %conv2.1, i32* @​a, align 4
ret void
}

llc -mtriple=i386--

    .text
    .file   "fuzz.ll"

llc: /home/simon/LLVM/llvm-project/llvm/include/llvm/CodeGen/SelectionDAGNodes.h:959: llvm::EVT llvm::SDNode::getValueType(unsigned int) const: Assertion `ResNo < NumValues && "Illegal result number!"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0. Program arguments: llc fuzz.ll -o - -mtriple=i386--

  1.  Running pass 'Function Pass Manager' on module 'fuzz.ll'.
    
  2.  Running pass 'X86 DAG->DAG Instruction Selection' on function '@c'
    

@rotateright
Copy link
Contributor

The bug is in DAGCombiner::foldSelectOfBinops(). That function handles binops that can produce more than 1 result, but it doesn't create new binops with the expected multiple results.

@rotateright
Copy link
Contributor

There were actually at least 3 bugs in this transform - 2 bugs on checking uses and 1 for producing the right values:
https://reviews.llvm.org/rG985b48f18341
https://reviews.llvm.org/rGe728d1a3e82b

@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 llvm:codegen
Projects
None yet
Development

No branches or pull requests

3 participants