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 @_ZTIi = external constant i8*
23 ; Function Attrs: uwtable
24 define void @_Z4testv() #0 {
26 %exn.slot = alloca i8*
27 %ehselector.slot = alloca i32
28 invoke void @_Z9may_throwv()
29 to label %invoke.cont unwind label %lpad
31 invoke.cont: ; preds = %entry
34 lpad: ; preds = %entry
35 %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
36 catch i8* bitcast (i8** @_ZTIi to i8*)
37 %1 = extractvalue { i8*, i32 } %0, 0
38 store i8* %1, i8** %exn.slot
39 %2 = extractvalue { i8*, i32 } %0, 1
40 store i32 %2, i32* %ehselector.slot
41 br label %catch.dispatch
43 catch.dispatch: ; preds = %lpad
44 %sel = load i32* %ehselector.slot
45 %3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #3
46 %matches = icmp eq i32 %sel, %3
47 br i1 %matches, label %catch, label %eh.resume
49 catch: ; preds = %catch.dispatch
50 %exn11 = load i8** %exn.slot
51 %4 = call i8* @llvm.eh.begincatch(i8* %exn11) #3
52 %5 = bitcast i8* %4 to i32*
53 call void @_Z10handle_intv()
54 br label %invoke.cont2
56 invoke.cont2: ; preds = %catch
57 call void @llvm.eh.endcatch() #3
60 try.cont: ; preds = %invoke.cont2, %invoke.cont
63 eh.resume: ; preds = %catch.dispatch
64 %exn3 = load i8** %exn.slot
65 %sel4 = load i32* %ehselector.slot
66 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn3, 0
67 %lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel4, 1
68 resume { i8*, i32 } %lpad.val5
71 ; CHECK: define i8* @_Z4testv.catch(i8*, i8*) {
73 ; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)
74 ; CHECK: %ehdata = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*
75 ; CHECK: %eh.obj.ptr = getelementptr inbounds %struct._Z4testv.ehdata* %ehdata, i32 0, i32 1
76 ; CHECK: %eh.obj = load i8** %eh.obj.ptr
77 ; CHECK: %2 = bitcast i8* %eh.obj to i32*
78 ; CHECK: call void @_Z10handle_intv()
79 ; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont)
82 declare void @_Z9may_throwv() #1
84 declare i32 @__CxxFrameHandler3(...)
86 ; Function Attrs: nounwind readnone
87 declare i32 @llvm.eh.typeid.for(i8*) #2
89 declare i8* @llvm.eh.begincatch(i8*)
91 declare void @llvm.eh.endcatch()
93 declare void @_Z10handle_intv() #1
95 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" }
96 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" }
97 attributes #2 = { nounwind readnone }
98 attributes #3 = { nounwind }
102 !0 = !{!"clang version 3.7.0 (trunk 227474) (llvm/trunk 227508)"}