title: Clang producing executable with illegal instruction
body: <p>I boiled the problem I'm seeing down to a small example.  Here is the LLVM assembler code I'm using (in foo.ll):</p>
  
  <pre><code>target datalayout = "e-p:64:64:64-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
  target triple = "x86_64-pc-linux-gnu"
  
  define fastcc i32 @foo(i32) {
  entry:
      %x = add i32 %0, 1
      ret i32 %x
  }
  
  define i32 @main(i32, i8**) {
  entry:
      %2 = call i32 @foo(i32 %0)
      ret i32 %2
  }
  </code></pre>
  
  <p>I then compile with:</p>
  
  <pre><code>clang -O1 -o foo foo.ll
  </code></pre>
  
  <p>... and when I run it I get:</p>
  
  <pre><code>Illegal instruction (core dumped)
  </code></pre>
  
  <p>... so I fire up my debugger, and see this:</p>
  
  <pre><code>Program received signal SIGILL, Illegal instruction.
  0x00000000004004d0 in main ()
  (gdb) bt
  #0  0x00000000004004d0 in main ()
  (gdb) disas
  Dump of assembler code for function main:
  =&gt; 0x00000000004004d0 &lt;+0&gt;: ud2    
  End of assembler dump.
  (gdb) 
  </code></pre>
  
  <p>Note that if I change either of the following the program executes fine:</p>
  
  <ul>
  <li>Remove -O1 from the clang flags</li>
  <li>Remove fastcc from the declaration of @foo in foo.ll</li>
  </ul>
  
  <p>For reference, "clang -v" is:</p>
  
  <pre><code>clang version 3.3 (tags/RELEASE_33/final)
  Target: x86_64-unknown-linux-gnu
  Thread model: posix
  </code></pre>
  
  <p>Also, if it helps <a href="http://pastebin.com/aYpRCbzd">here is the result of "objdump -d foo"</a>.</p>