<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - clang crashes at -O1 and above on x86_64-linux-gnu running pass 'Control Flow Optimizer'"
   href="https://llvm.org/bugs/show_bug.cgi?id=27750">27750</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang crashes at -O1 and above on x86_64-linux-gnu running pass 'Control Flow Optimizer'
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>helloqirun@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The current clang trunk crashes at -O1 and above when compiling the following
test case on x86_64-linux-gnu in both 32-bit and 64-bit modes.


$ clang-trunk -v
clang version 3.9.0 (trunk 269589)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/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.3
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/5.3.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/3.4.6
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.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.3.0
Found candidate GCC installation:
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0
Found candidate GCC installation:
/usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.3.0
Selected GCC installation: /usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64


$ clang-trunk -O3 abc.c
clang-3.9: /home/absozero/trunk/llvm/lib/Target/X86/X86InstrInfo.cpp:4241:
virtual unsigned int llvm::X86InstrInfo::InsertBranch(llvm::MachineBasicBlock
&, llvm::MachineBasicBlock *, llvm::MachineBasicBlock *,
ArrayRef<llvm::MachineOperand>, llvm::DebugLoc) const: Assertion `FBB && "MBB
cannot be the last block in function when the false " "body is a
fall-through."' failed.
#0 0x00000000019a2988 llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/home/absozero/trunk/root-clang/bin/clang-3.9+0x19a2988)
#1 0x00000000019a0e66 llvm::sys::RunSignalHandlers()
(/home/absozero/trunk/root-clang/bin/clang-3.9+0x19a0e66)
#2 0x00000000019a309e SignalHandler(int)
(/home/absozero/trunk/root-clang/bin/clang-3.9+0x19a309e)
#3 0x00007efdbb9df340 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x10340)
#4 0x00007efdbab91cc9 gsignal
/build/buildd/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
#5 0x00007efdbab950d8 abort /build/buildd/eglibc-2.19/stdlib/abort.c:91:0
#6 0x00007efdbab8ab86 __assert_fail_base
/build/buildd/eglibc-2.19/assert/assert.c:92:0
#7 0x00007efdbab8ac32 (/lib/x86_64-linux-gnu/libc.so.6+0x2fc32)
#8 0x00000000010b1240
llvm::X86InstrInfo::InsertBranch(llvm::MachineBasicBlock&,
llvm::MachineBasicBlock*, llvm::MachineBasicBlock*,
llvm::ArrayRef<llvm::MachineOperand>, llvm::DebugLoc) const
(/home/absozero/trunk/root-clang/bin/clang-3.9+0x10b1240)
#9 0x000000000145ca59
llvm::BranchFolder::TailMergeBlocks(llvm::MachineFunction&)
(/home/absozero/trunk/root-clang/bin/clang-3.9+0x145ca59)
#10 0x000000000145c0ab
llvm::BranchFolder::OptimizeFunction(llvm::MachineFunction&,
llvm::TargetInstrInfo const*, llvm::TargetRegisterInfo const*,
llvm::MachineModuleInfo*)
(/home/absozero/trunk/root-clang/bin/clang-3.9+0x145c0ab)
#11 0x0000000001463abe (anonymous
namespace)::BranchFolderPass::runOnMachineFunction(llvm::MachineFunction&)
(/home/absozero/trunk/root-clang/bin/clang-3.9+0x1463abe)
#12 0x000000000135abb5
llvm::MachineFunctionPass::runOnFunction(llvm::Function&)
(/home/absozero/trunk/root-clang/bin/clang-3.9+0x135abb5)
#13 0x00000000015a7a14 llvm::FPPassManager::runOnFunction(llvm::Function&)
(/home/absozero/trunk/root-clang/bin/clang-3.9+0x15a7a14)
#14 0x00000000015a7c5b llvm::FPPassManager::runOnModule(llvm::Module&)
(/home/absozero/trunk/root-clang/bin/clang-3.9+0x15a7c5b)
#15 0x00000000015a8127 llvm::legacy::PassManagerImpl::run(llvm::Module&)
(/home/absozero/trunk/root-clang/bin/clang-3.9+0x15a8127)
#16 0x0000000001afe528 clang::EmitBackendOutput(clang::DiagnosticsEngine&,
clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions
const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction,
llvm::raw_pwrite_stream*)
(/home/absozero/trunk/root-clang/bin/clang-3.9+0x1afe528)
#17 0x00000000022146ff
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&)
(/home/absozero/trunk/root-clang/bin/clang-3.9+0x22146ff)
#18 0x00000000025d6e56 clang::ParseAST(clang::Sema&, bool, bool)
(/home/absozero/trunk/root-clang/bin/clang-3.9+0x25d6e56)
#19 0x0000000001ecaee5 clang::FrontendAction::Execute()
(/home/absozero/trunk/root-clang/bin/clang-3.9+0x1ecaee5)
#20 0x0000000001e93911
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/home/absozero/trunk/root-clang/bin/clang-3.9+0x1e93911)
#21 0x0000000001f62276
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/home/absozero/trunk/root-clang/bin/clang-3.9+0x1f62276)
#22 0x000000000075859e cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/home/absozero/trunk/root-clang/bin/clang-3.9+0x75859e)
#23 0x0000000000756a43 main
(/home/absozero/trunk/root-clang/bin/clang-3.9+0x756a43)
#24 0x00007efdbab7cec5 __libc_start_main
/build/buildd/eglibc-2.19/csu/libc-start.c:321:0
#25 0x0000000000753fd2 _start
(/home/absozero/trunk/root-clang/bin/clang-3.9+0x753fd2)
Stack dump:
0.    Program arguments: /home/absozero/trunk/root-clang/bin/clang-3.9 -cc1
-triple x86_64-unknown-linux-gnu -emit-obj -disable-free -main-file-name abc.c
-mrelocation-model static -mthread-model posix -fmath-errno -masm-verbose
-mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64
-momit-leaf-frame-pointer -dwarf-column-info -debugger-tuning=gdb -resource-dir
/home/absozero/trunk/root-clang/bin/../lib/clang/3.9.0 -internal-isystem
/usr/local/include -internal-isystem
/home/absozero/trunk/root-clang/bin/../lib/clang/3.9.0/include
-internal-externc-isystem /usr/include/x86_64-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem /usr/include -O3
-fdebug-compilation-dir /home/absozero/projects/reduction/crash -ferror-limit
19 -fmessage-length 147 -fobjc-runtime=gcc -fdiagnostics-show-option
-fcolor-diagnostics -vectorize-loops -vectorize-slp -o /tmp/abc-8e9b33.o -x c
abc.c 
1.    <eof> parser at end of file
2.    Code generation
3.    Running pass 'Function Pass Manager' on module 'abc.c'.
4.    Running pass 'Control Flow Optimizer' on function '@fn1'
clang-3.9: error: unable to execute command: Aborted (core dumped)
clang-3.9: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 3.9.0 (trunk 269589)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
clang-3.9: note: diagnostic msg: PLEASE submit a bug report to
<a href="http://llvm.org/bugs/">http://llvm.org/bugs/</a> and include the crash backtrace, preprocessed source, and
associated run script.
clang-3.9: note: diagnostic msg: 
********************

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

********************


$ cat abc.c
int a, b;
float c;
void fn1() {
  int i;
  for (;; i++)
    for (; i;) {
      for (; b < 4; b++)
        c = a;
      if (c)
        i = 0;
    }
}</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>