<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 --- - Illegal Argument Generated by clang"
   href="https://llvm.org/bugs/show_bug.cgi?id=27432">27432</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Illegal Argument Generated by clang
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>jbkuszmaul@wpi.edu
          </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>Created <span class=""><a href="attachment.cgi?id=16240" name="attach_16240" title="C++ file that throws SIGILL when compiled & run">attachment 16240</a> <a href="attachment.cgi?id=16240&action=edit" title="C++ file that throws SIGILL when compiled & run">[details]</a></span>
C++ file that throws SIGILL when compiled & run

Here is the code that I am compiling, running, and having fail:

int foobar(int &foo) {
  foo *= 2;
}

int main(int argc, char * argv[]) {
  int foo = 100;
  foobar(foo);
}

As any compiler will warn you, I never actually return an int from foobar(),
which is definitely wrong, but the compilation succeeds, and I wouldn't
normally that to cause an issue.

Nevertheless, the program compiles, and when I run it I would expect no output
and success. Instead, I get:
Illegal instruction (core dumped)

>From gdb's disassembler:
Dump of assembler code for function _Z6foobarRi:
   0x00000000004005c0 <+0>:    push   %rbp
   0x00000000004005c1 <+1>:    mov    %rsp,%rbp
   0x00000000004005c4 <+4>:    mov    %rdi,-0x10(%rbp)
   0x00000000004005c8 <+8>:    mov    -0x10(%rbp),%rdi
   0x00000000004005cc <+12>:    mov    (%rdi),%eax
   0x00000000004005ce <+14>:    shl    $0x1,%eax
   0x00000000004005d1 <+17>:    mov    %eax,(%rdi)
=> 0x00000000004005d3 <+19>:    ud2 

The ud2 instruction is, for whatever reason, being generated and causing
SIGILL.

I assume that this is related to
<a href="http://stackoverflow.com/questions/19845474/clang-producing-executable-with-illegal-instruction">http://stackoverflow.com/questions/19845474/clang-producing-executable-with-illegal-instruction</a>
and
<a href="http://llvm.org/docs/FAQ.html#why-does-instcombine-simplifycfg-turn-a-call-to-a-function-with-a-mismatched-calling-convention-into-unreachable-why-not-make-the-verifier-reject-it">http://llvm.org/docs/FAQ.html#why-does-instcombine-simplifycfg-turn-a-call-to-a-function-with-a-mismatched-calling-convention-into-unreachable-why-not-make-the-verifier-reject-it</a>
. I do not know if there is an existing bug report/other documentation on this,
and although I would expect there to be, I don't really know where to find it.

However, because I feel like I am doing something that *should* work (even if
it's not entirely kosher), it seems like a bug that code that compiles with a
relatively innocuous seeming warning causes such a substantial fault (unless
there is something somewhere explicitly listing this as NOT being a bug).

Note that as soon as I either add a return statement to foobar() or make
foobar() return void, it starts working again (which is good).

When I install the nightly build of clang 3.9, or use the older version I
installed more normally (clang 3.6), I am able to reproduce this behavior.

Here is the version information for the compilers I've tried this with:

clang++-3.9 --version
clang version 3.9.0-svn266559-1~exp1 (trunk)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

clang++-3.6 --version
Ubuntu clang version 3.6.0-2ubuntu1~trusty1 (tags/RELEASE_360/final) (based on
LLVM 3.6.0)
Target: x86_64-pc-linux-gnu
Thread model: posix</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>