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 -pass-remarks-output=%t | FileCheck %s
4; RUN: cat %t | FileCheck %s --check-prefix=REMARKS
5
6; Repro cases from PR25168
7
8; test @catchret - catchret target is not address-taken until PEI
9; splits it into lea/mov followed by ret.  Make sure the MBB is
10; handled, both by tempting BranchFolding to merge it with %early_out
11; and delete it, and by checking that we emit a proper reference
12; to it in the LEA
13
14declare void @ProcessCLRException()
15declare void @f()
16
17define void @catchret(i1 %b) personality void ()* @ProcessCLRException {
18entry:
19  br i1 %b, label %body, label %early_out
20early_out:
21  ret void
22body:
23  invoke void @f()
24          to label %exit unwind label %catch.pad
25catch.pad:
26  %cs1 = catchswitch within none [label %catch.body] unwind to caller
27catch.body:
28  %catch = catchpad within %cs1 [i32 33554467]
29  catchret from %catch to label %exit
30exit:
31  ret void
32}
33; CHECK-LABEL: catchret:  # @catchret
34; CHECK: [[Exit:^[^ :]+]]: # Block address taken
35; CHECK-NEXT:              # %exit
36; CHECK: # %catch.body
37; CHECK: .seh_endprolog
38; CHECK: leaq [[Exit]](%rip), %rax
39; CHECK: retq # CATCHRET
40
41; REMARKS: Pass:            shrink-wrap
42; REMARKS-NEXT: Name:            UnsupportedEHFunclets
43; REMARKS-NEXT: Function:        catchret
44; REMARKS-NEXT: Args:
45; REMARKS-NEXT:   - String:          EH Funclets are not supported yet.
46
47; test @setjmp - similar to @catchret, but the MBB in question
48; is the one generated when the setjmp's block is split
49
50@buf = internal global [5 x i8*] zeroinitializer
51declare i8* @llvm.frameaddress(i32) nounwind readnone
52declare i8* @llvm.stacksave() nounwind
53declare i32 @llvm.eh.sjlj.setjmp(i8*) nounwind
54declare void @llvm.eh.sjlj.longjmp(i8*) nounwind
55
56define void @setjmp(i1 %b) nounwind {
57entry:
58  br i1 %b, label %early_out, label %sj
59early_out:
60  ret void
61sj:
62  %fp = call i8* @llvm.frameaddress(i32 0)
63  store i8* %fp, i8** getelementptr inbounds ([5 x i8*], [5 x i8*]* @buf, i64 0, i64 0), align 16
64  %sp = call i8* @llvm.stacksave()
65  store i8* %sp, i8** getelementptr inbounds ([5 x i8*], [5 x i8*]* @buf, i64 0, i64 2), align 16
66  call i32 @llvm.eh.sjlj.setjmp(i8* bitcast ([5 x i8*]* @buf to i8*))
67  ret void
68}
69; CHECK-LABEL: setjmp: # @setjmp
70; CHECK: # %sj
71; CHECK: leaq [[Label:\..+]](%rip), %[[Reg:.+]]{{$}}
72; CHECK-NEXT: movq %[[Reg]], buf
73; CHECK: {{^}}[[Label]]:  # Block address taken
74; CHECK-NEXT:              # %sj
75