return after trap

Jonas Paulsson via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 9 06:40:03 PDT 2017


> Ah, interesting.  Which is the "canonical" LLVM IR version?
>
> Can you check what clang generates from something like:
>
> void test (void)
> {
>   __builtin_trap();
> }
>
> or maybe:
>
> int test (void)
> {
>   __builtin_trap();
>   return 0;
> }
>
>
The clang front-end seems to generate

define void @test0() #0 {
entry:
   call void @llvm.trap()
   ret void
}

or

define signext i32 @test1() #0 {
entry:
   call void @llvm.trap()
   ret i32 0
}


At -O1 and higher these are both optimized to have the ret removed:

*** IR Dump After Simplify the CFG ***
; Function Attrs: nounwind
define void @test0() #0 {
entry:
   call void @llvm.trap()
   unreachable
}

, so only at -O0 is there a ret remaining.

/Jonas


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170609/7313fe63/attachment.html>


More information about the llvm-commits mailing list