[llvm-commits] [PATCH] __builtin_debugtrap() intrinsic function (change to Clang and CodeGen)
Eli Friedman
eli.friedman at gmail.com
Fri Oct 19 14:46:48 PDT 2012
On Fri, Oct 19, 2012 at 2:26 PM, Shuxin Yang <shuxin.llvm at gmail.com> wrote:
> Hi, Eli:
>
> Thank you for pointing out these problems.
>
> Not sure how debugger use __builtin_debugtrap(), I thought it should be
> flagged with "noreturn" like __builtin_trap(). Now I remove the attribute.
To clarify what I mean, try compiling and running the following
program under lldb:
#include <stdio.h>
int main() {
puts("before");
asm("int $3");
puts("after");
}
$ lldb /tmp/a
Current executable set to '/tmp/a' (x86_64).
(lldb) run
Process 53854 launched: '/private/tmp/a' (x86_64)
before
Process 53854 stopped
* thread #1: tid = 0x1c03, 0x0000000100000f2c a`main + 28, stop reason
= EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
frame #0: 0x0000000100000f2c a`main + 28
a`main + 28:
-> 0x100000f2c: movl %eax, -4(%rbp)
0x100000f2f: callq 0x100000f44 ; symbol stub for: puts
0x100000f34: movl $0, %ecx
0x100000f39: movl %eax, -8(%rbp)
(lldb) continue
Process 53854 resuming
after
Process 53854 exited with status = 0 (0x00000000)
(lldb) quit
As you can see, the "After" prints just fine. __builtin_debugbreak()
is supposed to work the same way as the inline assembler.
> There is a subtle problem here. If a programmer replace __builtin_trap()
> with __builtin_debugtrap(), the discrepancy between these two functions with
> regard to the "noreturn" will not incur correctness problem. However,
> replacing __builtin_debugtrap() with __builtin_trap() might incur some
> problems depending on how compiler takes advantage of noreturn.
Yes, but people shouldn't be blindly using intrinsics without knowing
what they do anyway.
Patch looks fine; don't forget to update the clang side as well.
-Eli
More information about the llvm-commits
mailing list