llvm.org GIT mirror llvm / 1249487
[WinEH] Add some test cases I forgot to add to previous commits git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241510 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 5 years ago
2 changed file(s) with 258 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 ; RUN: opt -winehprepare -S -o - < %s | FileCheck %s
1
2 ; This test is based on the following code:
3 ;
4 ; extern "C" void may_throw();
5 ; extern "C" void handle_exception();
6 ; extern "C" void test() {
7 ; try {
8 ; may_throw();
9 ; } catch (...) {
10 ; handle_exception();
11 ; }
12 ; }
13
14 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
15 target triple = "i686-pc-windows-msvc"
16
17 ; The function entry in this case remains unchanged.
18 ; CHECK: define void @test()
19 ; CHECK: entry:
20 ; CHECK: invoke void @may_throw()
21 ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
22
23 define void @test() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
24 entry:
25 %exn.slot = alloca i8*
26 %ehselector.slot = alloca i32
27 invoke void @may_throw()
28 to label %invoke.cont unwind label %lpad
29
30 invoke.cont: ; preds = %entry
31 br label %try.cont
32
33 ; CHECK: [[LPAD_LABEL]]:{{[ ]+}}; preds = %entry
34 ; CHECK: landingpad { i8*, i32 }
35 ; CHECK-NEXT: catch i8* null
36 ; CHECK-NEXT: [[RECOVER:\%.+]] = call i8* (...) @llvm.eh.actions(i32 1, i8* null, i32 -1, i8* ()* @test.catch)
37 ; CHECK-NEXT: indirectbr i8* [[RECOVER]], [label %try.cont]
38
39 lpad: ; preds = %entry
40 %0 = landingpad { i8*, i32 }
41 catch i8* null
42 %1 = extractvalue { i8*, i32 } %0, 0
43 store i8* %1, i8** %exn.slot
44 %2 = extractvalue { i8*, i32 } %0, 1
45 store i32 %2, i32* %ehselector.slot
46 br label %catch
47
48 ; CHECK-NOT: catch:
49 ; CHECK-NOT: @handle_exception()
50
51 catch: ; preds = %lpad
52 %exn = load i8*, i8** %exn.slot
53 call void @llvm.eh.begincatch(i8* %exn, i8* null) #1
54 call void @handle_exception()
55 call void @llvm.eh.endcatch() #1
56 br label %try.cont
57
58 try.cont: ; preds = %catch, %invoke.cont
59 ret void
60
61 ; CHECK: }
62 }
63
64 ; CHECK: define internal i8* @test.catch()
65 ; CHECK: call i8* @llvm.frameaddress(i32 1)
66 ; CHECK: call i8* @llvm.x86.seh.recoverfp(i8* bitcast (void ()* @test to i8*), i8* %{{.*}})
67 ; CHECK: call void @handle_exception()
68 ; CHECK: ret i8* blockaddress(@test, %try.cont)
69 ; CHECK: }
70
71
72 declare void @may_throw() #0
73
74 declare i32 @__CxxFrameHandler3(...)
75
76 ; Function Attrs: nounwind
77 declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #1
78
79 declare void @handle_exception() #0
80
81 ; Function Attrs: nounwind
82 declare void @llvm.eh.endcatch() #1
83
84 attributes #0 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
85 attributes #1 = { nounwind }
0 ; RUN: opt -S -winehprepare < %s | FileCheck %s
1
2 ; Test case based on this code:
3 ;
4 ; extern "C" int _abnormal_termination();
5 ; #pragma intrinsic(_abnormal_termination)
6 ; extern "C" int printf(const char *, ...);
7 ; extern "C" void may_crash() {
8 ; *(volatile int *)0 = 42;
9 ; }
10 ; int main() {
11 ; int myres = 0;
12 ; __try {
13 ; __try {
14 ; may_crash();
15 ; } __finally {
16 ; printf("inner finally %d\n", _abnormal_termination());
17 ; may_crash();
18 ; }
19 ; } __finally {
20 ; printf("outer finally %d\n", _abnormal_termination());
21 ; }
22 ; }
23 ;
24 ; Note that if the inner finally crashes, the outer finally still runs. There
25 ; is nothing like a std::terminate call in this situation.
26
27 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
28 target triple = "i686-pc-windows-msvc"
29
30 $"\01??_C@_0BC@LHHILCPN@outer?5finally?5?$CFd?6?$AA@" = comdat any
31
32 $"\01??_C@_0BC@JELAHKN@inner?5finally?5?$CFd?6?$AA@" = comdat any
33
34 @"\01??_C@_0BC@LHHILCPN@outer?5finally?5?$CFd?6?$AA@" = linkonce_odr unnamed_addr constant [18 x i8] c"outer finally %d\0A\00", comdat, align 1
35 @"\01??_C@_0BC@JELAHKN@inner?5finally?5?$CFd?6?$AA@" = linkonce_odr unnamed_addr constant [18 x i8] c"inner finally %d\0A\00", comdat, align 1
36
37 ; Function Attrs: nounwind
38 define void @may_crash() #0 {
39 entry:
40 store volatile i32 42, i32* null, align 4
41 ret void
42 }
43
44 ; Function Attrs: nounwind
45 define i32 @main() #0 personality i8* bitcast (i32 (...)* @_except_handler3 to i8*) {
46 entry:
47 %myres = alloca i32, align 4
48 %exn.slot = alloca i8*
49 %ehselector.slot = alloca i32
50 store i32 0, i32* %myres, align 4
51 invoke void @may_crash() #4
52 to label %invoke.cont unwind label %lpad
53
54 invoke.cont: ; preds = %entry
55 %0 = call i8* @llvm.frameaddress(i32 0)
56 invoke void @"\01?fin$1@0@main@@"(i8 zeroext 0, i8* %0) #4
57 to label %invoke.cont.2 unwind label %lpad.1
58
59 invoke.cont.2: ; preds = %invoke.cont
60 %1 = call i8* @llvm.frameaddress(i32 0)
61 call void @"\01?fin$0@0@main@@"(i8 zeroext 0, i8* %1)
62 ret i32 0
63
64 lpad: ; preds = %entry
65 %2 = landingpad { i8*, i32 }
66 cleanup
67 %3 = extractvalue { i8*, i32 } %2, 0
68 store i8* %3, i8** %exn.slot
69 %4 = extractvalue { i8*, i32 } %2, 1
70 store i32 %4, i32* %ehselector.slot
71 %5 = call i8* @llvm.frameaddress(i32 0)
72 invoke void @"\01?fin$1@0@main@@"(i8 zeroext 1, i8* %5) #4
73 to label %invoke.cont.3 unwind label %lpad.1
74
75 lpad.1: ; preds = %lpad, %invoke.cont
76 %6 = landingpad { i8*, i32 }
77 cleanup
78 %7 = extractvalue { i8*, i32 } %6, 0
79 store i8* %7, i8** %exn.slot
80 %8 = extractvalue { i8*, i32 } %6, 1
81 store i32 %8, i32* %ehselector.slot
82 br label %ehcleanup
83
84 invoke.cont.3: ; preds = %lpad
85 br label %ehcleanup
86
87 ehcleanup: ; preds = %invoke.cont.3, %lpad.1
88 %9 = call i8* @llvm.frameaddress(i32 0)
89 call void @"\01?fin$0@0@main@@"(i8 zeroext 1, i8* %9)
90 br label %eh.resume
91
92 eh.resume: ; preds = %ehcleanup
93 %exn = load i8*, i8** %exn.slot
94 %sel = load i32, i32* %ehselector.slot
95 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn, 0
96 %lpad.val.4 = insertvalue { i8*, i32 } %lpad.val, i32 %sel, 1
97 resume { i8*, i32 } %lpad.val.4
98 }
99
100 ; CHECK-LABEL: define i32 @main()
101 ; CHECK: invoke void @may_crash()
102 ;
103 ; CHECK: landingpad { i8*, i32 }
104 ; CHECK-NEXT: cleanup
105 ; CHECK-NEXT: call i8* (...) @llvm.eh.actions(i32 0, void ()* @main.cleanup)
106 ; CHECK-NEXT: indirectbr
107 ;
108 ; CHECK: landingpad { i8*, i32 }
109 ; CHECK-NEXT: cleanup
110 ; CHECK-NEXT: call i8* (...) @llvm.eh.actions(i32 0, void ()* @main.cleanup.1)
111 ; CHECK-NEXT: indirectbr
112
113 ; CHECK-LABEL: define internal void @main.cleanup()
114 ; CHECK: call i8* @llvm.frameaddress(i32 1)
115 ; CHECK: call i8* @llvm.x86.seh.recoverfp(i8* bitcast (i32 ()* @main to i8*), i8* %{{.*}})
116 ; CHECK: call void @"\01?fin$1@0@main@@"(i8 zeroext 1, i8* %{{.*}})
117 ; CHECK: call void @"\01?fin$0@0@main@@"(i8 zeroext 1, i8* %{{.*}})
118
119 ; CHECK-LABEL: define internal void @main.cleanup.1()
120 ; CHECK: call i8* @llvm.frameaddress(i32 1)
121 ; CHECK: call i8* @llvm.x86.seh.recoverfp(i8* bitcast (i32 ()* @main to i8*), i8* %{{.*}})
122 ; CHECK: call void @"\01?fin$0@0@main@@"(i8 zeroext 1, i8* %{{.*}})
123
124 ; Function Attrs: noinline nounwind
125 define internal void @"\01?fin$0@0@main@@"(i8 zeroext %abnormal_termination, i8* %frame_pointer) #1 {
126 entry:
127 %frame_pointer.addr = alloca i8*, align 4
128 %abnormal_termination.addr = alloca i8, align 1
129 %0 = call i8* @llvm.frameaddress(i32 1)
130 %1 = call i8* @llvm.x86.seh.recoverfp(i8* bitcast (i32 ()* @main to i8*), i8* %0)
131 store i8* %frame_pointer, i8** %frame_pointer.addr, align 4
132 store i8 %abnormal_termination, i8* %abnormal_termination.addr, align 1
133 %2 = zext i8 %abnormal_termination to i32
134 %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @"\01??_C@_0BC@LHHILCPN@outer?5finally?5?$CFd?6?$AA@", i32 0, i32 0), i32 %2)
135 ret void
136 }
137
138 ; Function Attrs: nounwind readnone
139 declare i8* @llvm.frameaddress(i32) #2
140
141 ; Function Attrs: nounwind readnone
142 declare i8* @llvm.x86.seh.recoverfp(i8*, i8*) #2
143
144 declare i32 @printf(i8*, ...) #3
145
146 ; Function Attrs: noinline nounwind
147 define internal void @"\01?fin$1@0@main@@"(i8 zeroext %abnormal_termination, i8* %frame_pointer) #1 {
148 entry:
149 %frame_pointer.addr = alloca i8*, align 4
150 %abnormal_termination.addr = alloca i8, align 1
151 %0 = call i8* @llvm.frameaddress(i32 1)
152 %1 = call i8* @llvm.x86.seh.recoverfp(i8* bitcast (i32 ()* @main to i8*), i8* %0)
153 store i8* %frame_pointer, i8** %frame_pointer.addr, align 4
154 store i8 %abnormal_termination, i8* %abnormal_termination.addr, align 1
155 %2 = zext i8 %abnormal_termination to i32
156 %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @"\01??_C@_0BC@JELAHKN@inner?5finally?5?$CFd?6?$AA@", i32 0, i32 0), i32 %2)
157 call void @may_crash()
158 ret void
159 }
160
161 declare i32 @_except_handler3(...)
162
163 attributes #0 = { nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
164 attributes #1 = { noinline nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
165 attributes #2 = { nounwind readnone }
166 attributes #3 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
167 attributes #4 = { noinline }
168
169 !llvm.ident = !{!0}
170
171 !0 = !{!"clang version 3.7.0 "}