Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

clang crashes on valid code at -O1 and above: UNREACHABLE executed at /home/su/software/tmp/polly/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp:476! #35575

Open Quuxplusone opened 6 years ago

Quuxplusone commented 6 years ago
Bugzilla Link PR36602
Status NEW
Importance P enhancement
Reported by Zhendong Su (su@cs.ucdavis.edu)
Reported on 2018-03-05 13:36:01 -0800
Last modified on 2018-05-14 01:19:01 -0700
Version unspecified
Hardware PC All
CC ditaliano@apple.com, llvm-bugs@lists.llvm.org, llvm-dev@ndave.org, mikael.holmen@ericsson.com, vsk@apple.com
Fixed by commit(s)
Attachments fail.ll (275 bytes, text/plain)
Blocks
Blocked by
See also
Tested with trunk revision 326694.

$ clangpolly -v
clang version 7.0.0 (http://llvm.org/git/clang.git
26d4516ed3de4e70527ed6dd1b122ff03a3a7ba5) (http://llvm.org/git/llvm.git
022e5fa26f94e30bf52bcd4bfa4c72492ae2f23d)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/su/bin
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/5.4.0
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/6.0.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.4
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.3
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.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.0.0
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
$
$ clangpolly -O0 -c small.c
$
$ clangpolly -O1 -c small.c
Operand not processed?
t25: ch = br t27, BasicBlock:ch<lor.rhs7 0x919fae8>

UNREACHABLE executed at
/home/su/software/tmp/polly/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp:476!
#0 0x00000000021b376a llvm::sys::PrintStackTrace(llvm::raw_ostream&)
/home/su/software/tmp/polly/llvm/lib/Support/Unix/Signals.inc:402:0
#1 0x00000000021b15fe llvm::sys::RunSignalHandlers()
/home/su/software/tmp/polly/llvm/lib/Support/Signals.cpp:50:0
#2 0x00000000021b1772 SignalHandler(int)
/home/su/software/tmp/polly/llvm/lib/Support/Unix/Signals.inc:242:0
#3 0x00007f9e50248390 __restore_rt (/lib/x86_64-linux-
gnu/libpthread.so.0+0x11390)
#4 0x00007f9e4efba428 gsignal /build/glibc-bfm8X4/glibc-
2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0
#5 0x00007f9e4efbc02a abort /build/glibc-bfm8X4/glibc-2.23/stdlib/abort.c:91:0
#6 0x000000000216714a (/home/su/software/tmp/polly/llvm_build/bin/clang-
6.0+0x216714a)
#7 0x0000000002b3ee29 llvm::SDNode::getNumOperands() const
/home/su/software/tmp/polly/llvm/include/llvm/CodeGen/SelectionDAGNodes.h:829:0
#8 0x0000000002b3ee29 llvm::DAGTypeLegalizer::run()
/home/su/software/tmp/polly/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp:453:0
#9 0x0000000002b3f53a llvm::SmallVectorTemplateCommon<llvm::SDNode*,
void>::begin()
/home/su/software/tmp/polly/llvm/include/llvm/ADT/SmallVector.h:116:0
#10 0x0000000002b3f53a llvm::SmallVector<llvm::SDNode*, 128u>::~SmallVector()
/home/su/software/tmp/polly/llvm/include/llvm/ADT/SmallVector.h:871:0
#11 0x0000000002b3f53a llvm::DAGTypeLegalizer::~DAGTypeLegalizer()
/home/su/software/tmp/polly/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h:32:0
#12 0x0000000002b3f53a llvm::SelectionDAG::LegalizeTypes()
/home/su/software/tmp/polly/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp:1187:0
#13 0x0000000002b018e1 llvm::TimeRegion::~TimeRegion()
/home/su/software/tmp/polly/llvm/include/llvm/Support/Timer.h:152:0
#14 0x0000000002b018e1 llvm::NamedRegionTimer::~NamedRegionTimer()
/home/su/software/tmp/polly/llvm/include/llvm/Support/Timer.h:160:0
#15 0x0000000002b018e1 llvm::SelectionDAGISel::CodeGenAndEmitDAG()
/home/su/software/tmp/polly/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:760:0
#16 0x0000000002b0c1aa
llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&)
/home/su/software/tmp/polly/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1632:0
#17 0x0000000002b0e119
llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) [clone
.part.878] [clone .constprop.902]
/home/su/software/tmp/polly/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:467:0
#18 0x000000000153a434 (anonymous
namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&)
/home/su/software/tmp/polly/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp:177:0
#19 0x00000000019b1925
llvm::MachineFunctionPass::runOnFunction(llvm::Function&)
/home/su/software/tmp/polly/llvm/lib/CodeGen/MachineFunctionPass.cpp:62:0
#20 0x0000000001ce825b llvm::FPPassManager::runOnFunction(llvm::Function&)
/home/su/software/tmp/polly/llvm/lib/IR/LegacyPassManager.cpp:1520:0
#21 0x0000000001ce831c llvm::FPPassManager::runOnModule(llvm::Module&)
/home/su/software/tmp/polly/llvm/lib/IR/LegacyPassManager.cpp:1541:0
#22 0x0000000001ce7e5d runOnModule
/home/su/software/tmp/polly/llvm/lib/IR/LegacyPassManager.cpp:1597:0
#23 0x0000000001ce7e5d llvm::legacy::PassManagerImpl::run(llvm::Module&)
/home/su/software/tmp/polly/llvm/lib/IR/LegacyPassManager.cpp:1700:0
#24 0x000000000236d225 llvm::PrettyStackTraceString::~PrettyStackTraceString()
/home/su/software/tmp/polly/llvm/include/llvm/Support/PrettyStackTrace.h:52:0
#25 0x000000000236d225 EmitAssembly
/home/su/software/tmp/polly/llvm/tools/clang/lib/CodeGen/BackendUtil.cpp:807:0
#26 0x000000000236d225 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<llvm::raw_pwrite_stream> >)
/home/su/software/tmp/polly/llvm/tools/clang/lib/CodeGen/BackendUtil.cpp:1199:0
#27 0x0000000002bcc7c7 std::unique_ptr<llvm::raw_pwrite_stream,
std::default_delete<llvm::raw_pwrite_stream> >::~unique_ptr()
/usr/include/c++/5/bits/unique_ptr.h:235:0
#28 0x0000000002bcc7c7
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&)
/home/su/software/tmp/polly/llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:292:0
#29 0x00000000030d5b00 clang::ParseAST(clang::Sema&, bool, bool)
/home/su/software/tmp/polly/llvm/tools/clang/lib/Parse/ParseAST.cpp:164:0
#30 0x0000000002bcbc5f clang::CodeGenAction::ExecuteAction()
/home/su/software/tmp/polly/llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:1044:0
#31 0x000000000274d5de clang::FrontendAction::Execute()
/home/su/software/tmp/polly/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:904:0
#32 0x000000000271acd6
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
/home/su/software/tmp/polly/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:992:0
#33 0x00000000027ddc1b
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
/home/su/software/tmp/polly/llvm/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:255:0
#34 0x0000000000acfc78 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*)
/home/su/software/tmp/polly/llvm/tools/clang/tools/driver/cc1_main.cpp:221:0
#35 0x0000000000a43b40 ExecuteCC1Tool
/home/su/software/tmp/polly/llvm/tools/clang/tools/driver/driver.cpp:309:0
#36 0x0000000000a43b40 main
/home/su/software/tmp/polly/llvm/tools/clang/tools/driver/driver.cpp:389:0
#37 0x00007f9e4efa5830 __libc_start_main /build/glibc-bfm8X4/glibc-
2.23/csu/../csu/libc-start.c:325:0
#38 0x0000000000acc0a9 _start (/home/su/software/tmp/polly/llvm_build/bin/clang-
6.0+0xacc0a9)
Stack dump:
0.  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 -fno-escaping-block-tail-
calls -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/20180304-
clangpolly-m64-O3-build-180400/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 -O1 -fdebug-compilation-dir
/home/su/specres/good/20180304-clangpolly-m64-O3-build-180400 -ferror-limit 19 -
fmessage-length 116 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-
diagnostics -o small.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 '@fn1'
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
26d4516ed3de4e70527ed6dd1b122ff03a3a7ba5) (http://llvm.org/git/llvm.git
022e5fa26f94e30bf52bcd4bfa4c72492ae2f23d)
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-e235ce.c
clang-6.0: note: diagnostic msg: /tmp/small-e235ce.sh
clang-6.0: note: diagnostic msg:

********************
$

------------------------------------------

int a, c, d, e, f, g, h, i;
static int b;

void fn1 ()
{
  int k = 4, l = 0;
  if (f)
    goto L2;
  l = 2;
L1:
  d = -((k && a | l) | (i || e));
  e = ~d || h ^ c;
L2:
  k = g;
  if (b)
    goto L1;
  while (1)
    b++;
}
Quuxplusone commented 6 years ago

Attached fail.ll (275 bytes, text/plain): small ll reproducer

Quuxplusone commented 6 years ago
This looks exactly like the problem I described here:
http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20180312/533912.html

It was introduced in r325892 and can be reproduced with

llc -o - fail.ll -disable-cgp-branch-opts

Copy/pasting my short analysis from the email above:

I just took a quick look in the debugger and saw that in
DAGCombiner::rebuildSetCC() we end up at

     // Avoid missing important xor optimizations.
     while (SDValue Tmp = visitXOR(TheXor)) {
       // We don't have a XOR anymore, bail.
       if (Tmp.getOpcode() != ISD::XOR)
         return Tmp;

And when we do the above

  return Tmp;

Tmp is:

(gdb) p Tmp->dump()
t10: i1 = <<Deleted Node!>>

and this "Deleted Node" is then used to create a new brcond in
DAGCombiner::visitBRCOND:

     if (SDValue NewN1 = rebuildSetCC(N1))
       return DAG.getNode(ISD::BRCOND, SDLoc(N), MVT::Other, Chain,
NewN1, N2);
Quuxplusone commented 6 years ago

Was this fixed by r331985?

Quuxplusone commented 6 years ago
(In reply to Vedant Kumar from comment #3)
> Was this fixed by r331985?

It fixed the instance of the problem that I saw. I don't know about the variant
that Zhendong Su originally reported in this PR but it seems likely to me that
it does.