[llvm-bugs] [Bug 27230] New: Naked functions that return values are broken

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Apr 5 15:19:25 PDT 2016


            Bug ID: 27230
           Summary: Naked functions that return values are broken
           Product: clang
           Version: 3.7
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: hausen at gmx.at
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Naked functions that return values are compiled incorrectly as soon as
optimizations are turned on. Take the following example:

int foo(void) __attribute__((naked,noinline));
int foo(void) {
  // assembly as generated for "return 41;"
  asm volatile("mov $41,%%eax; retq" : : : "memory");
int main() {
  return foo()+1;

The program returns the intended value of 42 when compiling with -O0. With -O1
however, the call to foo is replaced with a jump and the program returns 41.

As far as I can tell, the issue is caused by the fact that the end of a naked
functions is "unreachable". This seems to cause optimization passes to make
incorrect assumptions about the behavior of such functions.

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/20160405/3b7ee8d9/attachment.html>

More information about the llvm-bugs mailing list