<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 in 32-bit and 64-bit modes. [llvm::Instruction::Instruction(llvm::Type *, unsigned int, llvm::Use *, unsigned int, llvm::Instruction *): Assertion `BB && "Instruction to insert before is not in a basic block!"' failed]"
   href="https://llvm.org/bugs/show_bug.cgi?id=26287">26287</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang crashes at -O1 in 32-bit and 64-bit modes. [llvm::Instruction::Instruction(llvm::Type *, unsigned int, llvm::Use *, unsigned int, llvm::Instruction *): Assertion `BB && "Instruction to insert before is not in a basic block!"' failed]
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>Common Code Generator Code
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>chengniansun@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 following code crashes the trunk at -O1 and above in both 32-bit and 64-bit
modes on x86_64-linux-gnu. 


$: clang-trunk -v
clang version 3.9.0 (trunk 258659)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8.5
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9.3
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.2.1
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.2.1
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
$: 
$: clang-trunk small.c -O1 -m32 
small.c:16:14: warning: expression result unused [-Wunused-value]
void fn2() { fn1; }
             ^~~
clang: /tmp/llvm/lib/IR/Instruction.cpp:30:
llvm::Instruction::Instruction(llvm::Type *, unsigned int, llvm::Use *,
unsigned int, llvm::Instruction *): Assertion `BB && "Instruction to insert
before is not in a basic block!"' failed.
0  clang           0x00000000030c8788
llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  clang           0x00000000030c8ef7
2  libpthread.so.0 0x00007fda1fc96340
3  libc.so.6       0x00007fda1eca0cc9 gsignal + 57
4  libc.so.6       0x00007fda1eca40d8 abort + 328
5  libc.so.6       0x00007fda1ec99b86
6  libc.so.6       0x00007fda1ec99c32
7  clang           0x0000000002fe00f4
llvm::Instruction::Instruction(llvm::Type*, unsigned int, llvm::Use*, unsigned
int, llvm::Instruction*) + 244
8  clang           0x0000000002fe874a
llvm::UnreachableInst::UnreachableInst(llvm::LLVMContext&, llvm::Instruction*)
+ 42
9  clang           0x0000000002ba973e
llvm::changeToUnreachable(llvm::Instruction*, bool) + 414
10 clang           0x00000000029c44d9
11 clang           0x000000000300bd75
llvm::legacy::PassManagerImpl::run(llvm::Module&) + 869
12 clang           0x0000000000a20543
clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions
const&, clang::TargetOptions const&, clang::LangOptions const&,
llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::raw_pwrite_stream*)
+ 9603
13 clang           0x0000000000a00728
14 clang           0x0000000000cb81e6 clang::ParseAST(clang::Sema&, bool, bool)
+ 582
15 clang           0x000000000078d805 clang::FrontendAction::Execute() + 69
16 clang           0x0000000000756821
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1153
17 clang           0x000000000073522c
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 3068
18 clang           0x000000000072aeb8 cc1_main(llvm::ArrayRef<char const*>,
char const*, void*) + 1176
19 clang           0x00000000007338df main + 12543
20 libc.so.6       0x00007fda1ec8bec5 __libc_start_main + 245
21 clang           0x000000000072a94d
Stack dump:
0.    Program arguments: /usr/local/clang-trunk/bin/clang -cc1 -triple
i386-unknown-linux-gnu -emit-obj -disable-free -main-file-name small.c
-mrelocation-model static -mthread-model posix -fmath-errno -masm-verbose
-mconstructor-aliases -fuse-init-array -target-cpu pentium4
-target-linker-version 2.24 -momit-leaf-frame-pointer -dwarf-column-info
-debugger-tuning=gdb -resource-dir
/usr/local/clang-trunk/bin/../lib/clang/3.9.0 -c-isystem . -c-isystem
/usr/local/include/csmith -internal-isystem /usr/local/include
-internal-isystem /usr/local/clang-trunk/bin/../lib/clang/3.9.0/include
-internal-externc-isystem /include -internal-externc-isystem /usr/include -O1
-fdebug-compilation-dir
/home/cnsun/reduced-compiler-bugs/instrument/20160124-clang-trunk-m64-g-O3-build-091927/delta
-ferror-limit 19 -fmessage-length 128 -fobjc-runtime=gcc
-fdiagnostics-show-option -fcolor-diagnostics -o
/home/cnsun/ramdisk/tmp/small-9f32e4.o -x c small.c 
1.    <eof> parser at end of file
2.    Per-module optimization passes
3.    Running pass 'Interprocedural Sparse Conditional Constant Propagation' on
module 'small.c'.
clang: error: unable to execute command: Aborted (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 3.9.0 (trunk 258659)
Target: i386-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang: 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: note: diagnostic msg: 
********************

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

********************
$: 
$: cat small.c
short a, b;
char c;
static int fn1() {
  int d;
lbl_984:
  d |= a;
  if (b)
    goto lbl_984;
  for (;;) {
    if (c)
      goto lbl_984;
    d++;
  }
}

void fn2() { fn1; }
$:</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>