[llvm-bugs] [Bug 27432] New: Illegal Argument Generated by clang

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Apr 19 19:09:09 PDT 2016


            Bug ID: 27432
           Summary: Illegal Argument Generated by clang
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: jbkuszmaul at wpi.edu
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 16240
  --> https://llvm.org/bugs/attachment.cgi?id=16240&action=edit
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;

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

I assume that this is related to
. 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

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160420/60ee576d/attachment-0001.html>

More information about the llvm-bugs mailing list