1 ; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
3 ; This test is based on the following code:
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.
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"
21 ; This is the structure that will get created for the frame allocation.
22 ; CHECK: %struct._Z4testv.ehdata = type { i32, i8*, i32 }
24 @_ZTIi = external constant i8*
26 ; The function entry will be rewritten like this.
27 ; CHECK: define void @_Z4testv() #0 {
29 ; CHECK: %frame.alloc = call i8* @llvm.frameallocate(i32 24)
30 ; CHECK: %eh.data = bitcast i8* %frame.alloc to %struct._Z4testv.ehdata*
31 ; CHECK: %exn.slot = alloca i8*
32 ; CHECK: %ehselector.slot = alloca i32
33 ; CHECK-NOT: %i = alloca i32, align 4
34 ; CHECK: %i = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 2
36 ; Function Attrs: uwtable
37 define void @_Z4testv() #0 {
39 %exn.slot = alloca i8*
40 %ehselector.slot = alloca i32
41 %i = alloca i32, align 4
42 invoke void @_Z9may_throwv()
43 to label %invoke.cont unwind label %lpad
45 invoke.cont: ; preds = %entry
48 lpad: ; preds = %entry
49 %tmp = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
50 catch i8* bitcast (i8** @_ZTIi to i8*)
51 %tmp1 = extractvalue { i8*, i32 } %tmp, 0
52 store i8* %tmp1, i8** %exn.slot
53 %tmp2 = extractvalue { i8*, i32 } %tmp, 1
54 store i32 %tmp2, i32* %ehselector.slot
55 br label %catch.dispatch
57 catch.dispatch: ; preds = %lpad
58 %sel = load i32, i32* %ehselector.slot
59 %tmp3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #3
60 %matches = icmp eq i32 %sel, %tmp3
61 br i1 %matches, label %catch, label %eh.resume
63 catch: ; preds = %catch.dispatch
64 %exn11 = load i8*, i8** %exn.slot
65 %i.i8 = bitcast i32* %i to i8*
66 call void @llvm.eh.begincatch(i8* %exn11, i8* %i.i8) #3
67 %tmp7 = load i32, i32* %i, align 4
68 call void @_Z10handle_inti(i32 %tmp7)
69 br label %invoke.cont2
71 invoke.cont2: ; preds = %catch
72 call void @llvm.eh.endcatch() #3
75 try.cont: ; preds = %invoke.cont2, %invoke.cont
78 eh.resume: ; preds = %catch.dispatch
79 %exn3 = load i8*, i8** %exn.slot
80 %sel4 = load i32, i32* %ehselector.slot
81 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn3, 0
82 %lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel4, 1
83 resume { i8*, i32 } %lpad.val5
86 ; CHECK: define internal i8* @_Z4testv.catch(i8*, i8*) {
88 ; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)
89 ; CHECK: %eh.data = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*
90 ; CHECK: %eh.obj.ptr = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 1
91 ; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr
92 ; CHECK: %i = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 2
93 ; CHECK: %tmp7 = load i32, i32* %i, align 4
94 ; CHECK: call void @_Z10handle_inti(i32 %tmp7)
95 ; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont)
98 declare void @_Z9may_throwv() #1
100 declare i32 @__CxxFrameHandler3(...)
102 ; Function Attrs: nounwind readnone
103 declare i32 @llvm.eh.typeid.for(i8*) #2
105 declare void @llvm.eh.begincatch(i8*, i8*)
107 declare void @llvm.eh.endcatch()
109 declare void @_Z10handle_inti(i32) #1
111 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" }
112 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" }
113 attributes #2 = { nounwind readnone }
114 attributes #3 = { nounwind }
118 !0 = !{!"clang version 3.7.0 (trunk 227474) (llvm/trunk 227508)"}