Replace llvm.frameallocate with llvm.frameescape
[oota-llvm.git] / test / CodeGen / WinEH / cppeh-catch-scalar.ll
1 ; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
2
3 ; This test is based on the following code:
4 ;
5 ; void test()
6 ; {
7 ;   try {
8 ;     may_throw();
9 ;   } catch (int i) {
10 ;     handle_int(i);
11 ;   }
12 ; }
13 ;
14 ; Parts of the IR have been hand-edited to simplify the test case.
15 ; The full IR will be restored when Windows C++ EH support is complete.
16
17 ;ModuleID = 'cppeh-catch-scalar.cpp'
18 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
19 target triple = "x86_64-pc-windows-msvc"
20
21 @_ZTIi = external constant i8*
22
23 ; The function entry will be rewritten like this.
24 ; CHECK: define void @_Z4testv() #0 {
25 ; CHECK: entry:
26 ; CHECK:   %exn.slot = alloca i8*
27 ; CHECK:   %ehselector.slot = alloca i32
28 ; CHECK:   %i = alloca i32, align 4
29 ; CHECK:   call void (...)* @llvm.frameescape(i32* %i)
30 ; CHECK:   invoke void @_Z9may_throwv()
31 ; CHECK:           to label %invoke.cont unwind label %lpad
32
33 ; Function Attrs: uwtable
34 define void @_Z4testv() #0 {
35 entry:
36   %exn.slot = alloca i8*
37   %ehselector.slot = alloca i32
38   %i = alloca i32, align 4
39   invoke void @_Z9may_throwv()
40           to label %invoke.cont unwind label %lpad
41
42 invoke.cont:                                      ; preds = %entry
43   br label %try.cont
44
45 lpad:                                             ; preds = %entry
46   %tmp = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
47           catch i8* bitcast (i8** @_ZTIi to i8*)
48   %tmp1 = extractvalue { i8*, i32 } %tmp, 0
49   store i8* %tmp1, i8** %exn.slot
50   %tmp2 = extractvalue { i8*, i32 } %tmp, 1
51   store i32 %tmp2, i32* %ehselector.slot
52   br label %catch.dispatch
53
54 catch.dispatch:                                   ; preds = %lpad
55   %sel = load i32, i32* %ehselector.slot
56   %tmp3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #3
57   %matches = icmp eq i32 %sel, %tmp3
58   br i1 %matches, label %catch, label %eh.resume
59
60 catch:                                            ; preds = %catch.dispatch
61   %exn11 = load i8*, i8** %exn.slot
62   %i.i8 = bitcast i32* %i to i8*
63   call void @llvm.eh.begincatch(i8* %exn11, i8* %i.i8) #3
64   %tmp7 = load i32, i32* %i, align 4
65   call void @_Z10handle_inti(i32 %tmp7)
66   br label %invoke.cont2
67
68 invoke.cont2:                                     ; preds = %catch
69   call void @llvm.eh.endcatch() #3
70   br label %try.cont
71
72 try.cont:                                         ; preds = %invoke.cont2, %invoke.cont
73   ret void
74
75 eh.resume:                                        ; preds = %catch.dispatch
76   %exn3 = load i8*, i8** %exn.slot
77   %sel4 = load i32, i32* %ehselector.slot
78   %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn3, 0
79   %lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel4, 1
80   resume { i8*, i32 } %lpad.val5
81 }
82
83 ; CHECK: define internal i8* @_Z4testv.catch(i8*, i8*) {
84 ; CHECK: entry:
85 ; CHECK:   %i.i81 = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1, i32 0)
86 ; CHECK:   %i = bitcast i8* %i.i81 to i32*
87 ; CHECK:   %tmp7 = load i32, i32* %i, align 4
88 ; CHECK:   call void @_Z10handle_inti(i32 %tmp7)
89 ; CHECK:   ret i8* blockaddress(@_Z4testv, %try.cont)
90 ; CHECK: }
91
92 declare void @_Z9may_throwv() #1
93
94 declare i32 @__CxxFrameHandler3(...)
95
96 ; Function Attrs: nounwind readnone
97 declare i32 @llvm.eh.typeid.for(i8*) #2
98
99 declare void @llvm.eh.begincatch(i8*, i8*)
100
101 declare void @llvm.eh.endcatch()
102
103 declare void @_Z10handle_inti(i32) #1
104
105 attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
106 attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
107 attributes #2 = { nounwind readnone }
108 attributes #3 = { nounwind }
109
110 !llvm.ident = !{!0}
111
112 !0 = !{!"clang version 3.7.0 (trunk 227474) (llvm/trunk 227508)"}