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 %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
50 catch i8* bitcast (i8** @_ZTIi to i8*)
51 %1 = extractvalue { i8*, i32 } %0, 0
52 store i8* %1, i8** %exn.slot
53 %2 = extractvalue { i8*, i32 } %0, 1
54 store i32 %2, i32* %ehselector.slot
55 br label %catch.dispatch
57 catch.dispatch: ; preds = %lpad
58 %sel = load i32* %ehselector.slot
59 %3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #3
60 %matches = icmp eq i32 %sel, %3
61 br i1 %matches, label %catch, label %eh.resume
63 catch: ; preds = %catch.dispatch
64 %exn11 = load i8** %exn.slot
65 %4 = call i8* @llvm.eh.begincatch(i8* %exn11) #3
66 %5 = bitcast i8* %4 to i32*
67 %6 = load i32* %5, align 4
68 store i32 %6, i32* %i, align 4
69 %7 = load i32* %i, align 4
70 call void @_Z10handle_inti(i32 %7)
71 br label %invoke.cont2
73 invoke.cont2: ; preds = %catch
74 call void @llvm.eh.endcatch() #3
77 try.cont: ; preds = %invoke.cont2, %invoke.cont
80 eh.resume: ; preds = %catch.dispatch
81 %exn3 = load i8** %exn.slot
82 %sel4 = load i32* %ehselector.slot
83 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn3, 0
84 %lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel4, 1
85 resume { i8*, i32 } %lpad.val5
88 ; CHECK: define i8* @_Z4testv.catch(i8*, i8*) {
90 ; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)
91 ; CHECK: %eh.data = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*
92 ; CHECK: %eh.obj.ptr = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 1
93 ; CHECK: %eh.obj = load i8** %eh.obj.ptr
94 ; CHECK: %i = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 2
95 ; CHECK: %2 = bitcast i8* %eh.obj to i32*
96 ; CHECK: %3 = load i32* %2, align 4
97 ; CHECK: store i32 %3, i32* %i, align 4
98 ; CHECK: %4 = load i32* %i, align 4
99 ; CHECK: call void @_Z10handle_inti(i32 %4)
100 ; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont)
103 declare void @_Z9may_throwv() #1
105 declare i32 @__CxxFrameHandler3(...)
107 ; Function Attrs: nounwind readnone
108 declare i32 @llvm.eh.typeid.for(i8*) #2
110 declare i8* @llvm.eh.begincatch(i8*)
112 declare void @llvm.eh.endcatch()
114 declare void @_Z10handle_inti(i32) #1
116 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" }
117 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" }
118 attributes #2 = { nounwind readnone }
119 attributes #3 = { nounwind }
123 !0 = !{!"clang version 3.7.0 (trunk 227474) (llvm/trunk 227508)"}