[IR] Reformulate LLVM's EH funclet IR
[oota-llvm.git] / test / CodeGen / X86 / late-address-taken.ll
1 ; RUN: llc -mtriple=x86_64-pc-windows-msvc < %s -enable-shrink-wrap=false | FileCheck %s
2 ; Make sure shrink-wrapping does not break the lowering of exception handling.
3 ; RUN: llc -mtriple=x86_64-pc-windows-msvc < %s -enable-shrink-wrap=true | FileCheck %s
4
5 ; Repro cases from PR25168
6
7 ; test @catchret - catchret target is not address-taken until PEI
8 ; splits it into lea/mov followed by ret.  Make sure the MBB is
9 ; handled, both by tempting BranchFolding to merge it with %early_out
10 ; and delete it, and by checking that we emit a proper reference
11 ; to it in the LEA
12
13 declare void @ProcessCLRException()
14 declare void @f()
15
16 define void @catchret(i1 %b) personality void ()* @ProcessCLRException {
17 entry:
18   br i1 %b, label %body, label %early_out
19 early_out:
20   ret void
21 body:
22   invoke void @f()
23           to label %exit unwind label %catch.pad
24 catch.pad:
25   %cs1 = catchswitch within none [label %catch.body] unwind to caller
26 catch.body:
27   %catch = catchpad within %cs1 [i32 33554467]
28   catchret from %catch to label %exit
29 exit:
30   ret void
31 }
32 ; CHECK-LABEL: catchret:  # @catchret
33 ; CHECK: [[Exit:^[^ :]+]]: # Block address taken
34 ; CHECK-NEXT:              # %exit
35 ; CHECK: # %catch.body
36 ; CHECK: .seh_endprolog
37 ; CHECK: leaq [[Exit]](%rip), %rax
38 ; CHECK: retq # CATCHRET
39
40
41 ; test @setjmp - similar to @catchret, but the MBB in question
42 ; is the one generated when the setjmp's block is split
43
44 @buf = internal global [5 x i8*] zeroinitializer
45 declare i8* @llvm.frameaddress(i32) nounwind readnone
46 declare i8* @llvm.stacksave() nounwind
47 declare i32 @llvm.eh.sjlj.setjmp(i8*) nounwind
48 declare void @llvm.eh.sjlj.longjmp(i8*) nounwind
49
50 define void @setjmp(i1 %b) nounwind {
51 entry:
52   br i1 %b, label %early_out, label %sj
53 early_out:
54   ret void
55 sj:
56   %fp = call i8* @llvm.frameaddress(i32 0)
57   store i8* %fp, i8** getelementptr inbounds ([5 x i8*], [5 x i8*]* @buf, i64 0, i64 0), align 16
58   %sp = call i8* @llvm.stacksave()
59   store i8* %sp, i8** getelementptr inbounds ([5 x i8*], [5 x i8*]* @buf, i64 0, i64 2), align 16
60   call i32 @llvm.eh.sjlj.setjmp(i8* bitcast ([5 x i8*]* @buf to i8*))
61   ret void
62 }
63 ; CHECK-LABEL: setjmp: # @setjmp
64 ; CHECK: # %sj
65 ; CHECK: leaq [[Label:\..+]](%rip), %[[Reg:.+]]{{$}}
66 ; CHECK-NEXT: movq %[[Reg]], buf
67 ; CHECK: {{^}}[[Label]]:  # Block address taken
68 ; CHECK-NEXT:              # %sj