[LLVMbugs] [Bug 15047] New: Calls to no-return functions at end of a function need to be tail-call or followed by a nop

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jan 22 16:05:24 PST 2013


http://llvm.org/bugs/show_bug.cgi?id=15047

             Bug #: 15047
           Summary: Calls to no-return functions at end of a function need
                    to be tail-call or followed by a nop
           Product: new-bugs
           Version: 3.1
          Platform: Macintosh
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: paul.q.stevenson at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Compiling the code below with clang -O2 generates code that skips restoring
registers (since throw_exception() does not return) but which still uses a
callq/blx instruction rather than a jmpq/bx instruction.  This breaks unwind
tables, since the call to f() is still in the call stack, but with the
instruction pointer in the next function in the object file.  Trying to unwind
from further down the stack chain will access the wrong unwind table.

The code should either restore registers and use a tail call (so removing
itself from the call stack), or it should include an unreachable nop after the
non-returning call (so that the instruction pointer is still within the
function bounds).

Clang version: (Apple clang version 4.0 (tags/Apple/clang-421.0.57) (based on
LLVM 3.1svn))

C code:

extern void throw_exception(void) __attribute__((noreturn));

void f(void)
{
    throw_exception();
}

compiled with -target x86_64-apple-darwin11.4.2:

__TEXT,__text) section
_f:
0000000000000000    pushq    %rbp
0000000000000001    movq    %rsp, %rbp
0000000000000004    popq    %rbp
0000000000000005    jmpq    0x9

compiled with -target armv7-apple-darwin11.4.2:

(__TEXT,__text) section
_f:
00000000        b580    push    {r7, lr}
00000002        466f    mov    r7, sp
00000004    f7ffeffc    blx    0x0

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list