[SEH] Update SEH codegen tests to use the new IR
[oota-llvm.git] / test / CodeGen / WinEH / seh-resume-phi.ll
1 ; RUN: opt -S -winehprepare -mtriple=x86_64-pc-windows-msvc < %s | FileCheck %s
2 ; RUN: opt -S -winehprepare -mtriple=x86_64-pc-windows-coreclr < %s | FileCheck %s
3
4 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
5
6 declare void @might_crash(i8* %ehptr)
7 declare i32 @filt()
8 declare void @cleanup()
9 declare i32 @__C_specific_handler(...)
10 declare i32 @llvm.eh.typeid.for(i8*)
11
12 define void @resume_phi() personality i32 (...)* @__C_specific_handler {
13 entry:
14   invoke void @might_crash(i8* null)
15           to label %return unwind label %lpad1
16
17 lpad1:
18   %ehvals1 = landingpad { i8*, i32 }
19           catch i32 ()* @filt
20   %ehptr1 = extractvalue { i8*, i32 } %ehvals1, 0
21   %ehsel1 = extractvalue { i8*, i32 } %ehvals1, 1
22   %filt_sel = tail call i32 @llvm.eh.typeid.for(i8* bitcast (i32 ()* @filt to i8*))
23   %matches = icmp eq i32 %ehsel1, %filt_sel
24   br i1 %matches, label %__except, label %eh.resume
25
26 __except:
27   invoke void @might_crash(i8* %ehptr1)
28           to label %return unwind label %lpad2
29
30 lpad2:
31   %ehvals2 = landingpad { i8*, i32 }
32           cleanup
33   %ehptr2 = extractvalue { i8*, i32 } %ehvals2, 0
34   %ehsel2 = extractvalue { i8*, i32 } %ehvals2, 1
35   call void @cleanup()
36   br label %eh.resume
37
38 return:
39   ret void
40
41 eh.resume:
42   %ehptr.phi = phi i8* [ %ehptr1, %lpad1 ], [ %ehptr2, %lpad2 ]
43   %ehsel.phi = phi i32 [ %ehsel1, %lpad1 ], [ %ehsel2, %lpad2 ]
44   %ehval.phi1 = insertvalue { i8*, i32 } undef, i8* %ehptr.phi, 0
45   %ehval.phi2 = insertvalue { i8*, i32 } %ehval.phi1, i32 %ehsel.phi, 1
46   resume { i8*, i32 } %ehval.phi2
47 }
48
49 ; CHECK-LABEL: define void @resume_phi()
50 ; CHECK: invoke void @might_crash(i8* null)
51 ; CHECK: landingpad { i8*, i32 }
52 ; CHECK-NEXT: catch i32 ()* @filt
53 ; CHECK-NEXT: call i8* (...) @llvm.eh.actions(
54 ; CHECK-SAME: i32 1, i8* bitcast (i32 ()* @filt to i8*), i32 -1, i8* blockaddress(@resume_phi, %__except))
55 ; CHECK-NEXT: indirectbr {{.*}} [label %__except]
56 ;
57 ; CHECK: __except:
58 ; CHECK: call i32 @llvm.eh.exceptioncode.old()
59 ; CHECK: invoke void @might_crash(i8* %{{.*}})
60 ; CHECK: landingpad { i8*, i32 }
61 ; CHECK-NEXT: cleanup
62 ; CHECK-NEXT: call i8* (...) @llvm.eh.actions(i32 0, void (i8*, i8*)* @resume_phi.cleanup)
63 ; CHECK-NEXT: indirectbr {{.*}} []
64
65 ; CHECK-LABEL: define internal void @resume_phi.cleanup(i8*, i8*)
66 ; CHECK: call void @cleanup()