[SEH] Update SEH codegen tests to use the new IR
[oota-llvm.git] / test / CodeGen / X86 / seh-except-finally.ll
1 ; RUN: llc < %s | FileCheck %s
2
3 ; Test case based on this source:
4 ; int puts(const char*);
5 ; __declspec(noinline) void crash() {
6 ;   *(volatile int*)0 = 42;
7 ; }
8 ; int filt();
9 ; void use_both() {
10 ;   __try {
11 ;     __try {
12 ;       crash();
13 ;     } __finally {
14 ;       puts("__finally");
15 ;     }
16 ;   } __except (filt()) {
17 ;     puts("__except");
18 ;   }
19 ; }
20
21 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
22 target triple = "x86_64-pc-windows-msvc"
23
24 $"\01??_C@_09KJEHOMHG@__finally?$AA@" = comdat any
25
26 $"\01??_C@_08MLCMLGHM@__except?$AA@" = comdat any
27
28 @"\01??_C@_09KJEHOMHG@__finally?$AA@" = linkonce_odr unnamed_addr constant [10 x i8] c"__finally\00", comdat, align 1
29 @"\01??_C@_08MLCMLGHM@__except?$AA@" = linkonce_odr unnamed_addr constant [9 x i8] c"__except\00", comdat, align 1
30
31 declare void @crash()
32
33 declare i32 @filt()
34
35 ; Function Attrs: nounwind uwtable
36 define void @use_both() #1 personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) {
37 entry:
38   %exn.slot = alloca i8*
39   %ehselector.slot = alloca i32
40   invoke void @crash() #5
41           to label %invoke.cont unwind label %__finally
42
43 invoke.cont:                                      ; preds = %entry
44   %0 = call i8* @llvm.localaddress()
45   invoke void @"\01?fin$0@0@use_both@@"(i1 zeroext false, i8* %0) #5
46           to label %invoke.cont2 unwind label %catch.dispatch
47
48 invoke.cont2:                                     ; preds = %invoke.cont
49   br label %__try.cont
50
51 __finally:                                             ; preds = %entry
52   %cleanuppad = cleanuppad []
53   %locals = call i8* @llvm.localaddress()
54   invoke void @"\01?fin$0@0@use_both@@"(i1 zeroext true, i8* %locals) #5
55           to label %invoke.cont3 unwind label %cleanupendpad
56
57 invoke.cont3:                                     ; preds = %__finally
58   cleanupret %cleanuppad unwind label %catch.dispatch
59
60 cleanupendpad:
61   cleanupendpad %cleanuppad unwind label %catch.dispatch
62
63 catch.dispatch:                                   ; preds = %invoke.cont3, %lpad1
64   %catchpad = catchpad [i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@use_both@@" to i8*)]
65           to label %__except unwind label %catchendpad
66
67 __except:                                         ; preds = %catch.dispatch
68   %call = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @"\01??_C@_08MLCMLGHM@__except?$AA@", i32 0, i32 0))
69   catchret %catchpad to label %__try.cont
70
71 catchendpad:
72   catchendpad unwind to caller
73
74 __try.cont:                                       ; preds = %__except, %invoke.cont2
75   ret void
76
77 eh.resume:                                        ; preds = %catch.dispatch
78   %exn = load i8*, i8** %exn.slot
79   %sel4 = load i32, i32* %ehselector.slot
80   %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn, 0
81   %lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel4, 1
82   resume { i8*, i32 } %lpad.val5
83 }
84
85 ; CHECK-LABEL: use_both:
86 ; CHECK: .Ltmp0
87 ; CHECK: callq crash
88 ; CHECK: .Ltmp1
89 ; CHECK: .Ltmp4
90 ; CHECK: callq "?fin$0@0@use_both@@"
91 ; CHECK: .Ltmp5
92 ; CHECK: retq
93 ;
94 ; CHECK: .seh_handlerdata
95 ; CHECK-NEXT: .long (.Llsda_end0-.Llsda_begin0)/16
96 ; CHECK-NEXT: .Llsda_begin0:
97 ; CHECK-NEXT: .long .Ltmp0@IMGREL+1
98 ; CHECK-NEXT: .long .Ltmp1@IMGREL+1
99 ; CHECK-NEXT: .long "?dtor$2@?0?use_both@4HA"@IMGREL
100 ; CHECK-NEXT: .long 0
101 ; CHECK-NEXT: .long .Ltmp0@IMGREL+1
102 ; CHECK-NEXT: .long .Ltmp1@IMGREL+1
103 ; CHECK-NEXT: .long "?filt$0@0@use_both@@"@IMGREL
104 ; CHECK-NEXT: .long .LBB0_{{[0-9]+}}@IMGREL
105 ; CHECK-NEXT: .long .Ltmp4@IMGREL+1
106 ; CHECK-NEXT: .long .Ltmp5@IMGREL+1
107 ; CHECK-NEXT: .long "?filt$0@0@use_both@@"@IMGREL
108 ; CHECK-NEXT: .long .LBB0_{{[0-9]+}}@IMGREL
109 ; CHECK-NEXT: .Llsda_end0:
110
111 ; Function Attrs: noinline nounwind
112 define internal i32 @"\01?filt$0@0@use_both@@"(i8* %exception_pointers, i8* %frame_pointer) #2 {
113 entry:
114   %frame_pointer.addr = alloca i8*, align 8
115   %exception_pointers.addr = alloca i8*, align 8
116   %exn.slot = alloca i8*
117   store i8* %frame_pointer, i8** %frame_pointer.addr, align 8
118   store i8* %exception_pointers, i8** %exception_pointers.addr, align 8
119   %0 = load i8*, i8** %exception_pointers.addr
120   %1 = bitcast i8* %0 to { i32*, i8* }*
121   %2 = getelementptr inbounds { i32*, i8* }, { i32*, i8* }* %1, i32 0, i32 0
122   %3 = load i32*, i32** %2
123   %4 = load i32, i32* %3
124   %5 = zext i32 %4 to i64
125   %6 = inttoptr i64 %5 to i8*
126   store i8* %6, i8** %exn.slot
127   %call = call i32 @filt()
128   ret i32 %call
129 }
130
131 define internal void @"\01?fin$0@0@use_both@@"(i1 zeroext %abnormal_termination, i8* %frame_pointer) #3 {
132 entry:
133   %frame_pointer.addr = alloca i8*, align 8
134   %abnormal_termination.addr = alloca i8, align 1
135   store i8* %frame_pointer, i8** %frame_pointer.addr, align 8
136   %frombool = zext i1 %abnormal_termination to i8
137   store i8 %frombool, i8* %abnormal_termination.addr, align 1
138   %call = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @"\01??_C@_09KJEHOMHG@__finally?$AA@", i32 0, i32 0))
139   ret void
140 }
141
142 declare i32 @puts(i8*) #3
143
144 declare i32 @__C_specific_handler(...)
145
146 ; Function Attrs: nounwind readnone
147 declare i8* @llvm.localaddress() #4
148
149 ; Function Attrs: nounwind readnone
150 declare i32 @llvm.eh.typeid.for(i8*) #4
151
152 attributes #0 = { noinline nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
153 attributes #1 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
154 attributes #2 = { noinline nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
155 attributes #3 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
156 attributes #4 = { nounwind readnone }
157 attributes #5 = { noinline }
158 attributes #6 = { nounwind }