1 ; RUN: opt -winehprepare -S -o - < %s | FileCheck %s
3 ; This test is based on the following code:
5 ; extern "C" void may_throw();
6 ; extern "C" void handle_exception();
7 ; extern "C" void test() {
15 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
16 target triple = "i686-pc-windows-msvc"
18 ; The function entry in this case remains unchanged.
19 ; CHECK: define void @test()
21 ; CHECK: invoke void @may_throw()
22 ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
24 define void @test() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
26 %exn.slot = alloca i8*
27 %ehselector.slot = alloca i32
28 invoke void @may_throw()
29 to label %invoke.cont unwind label %lpad
31 invoke.cont: ; preds = %entry
34 ; CHECK: [[LPAD_LABEL]]:{{[ ]+}}; preds = %entry
35 ; CHECK: landingpad { i8*, i32 }
36 ; CHECK-NEXT: catch i8* null
37 ; CHECK-NEXT: [[RECOVER:\%.+]] = call i8* (...) @llvm.eh.actions(i32 1, i8* null, i32 -1, i8* ()* @test.catch)
38 ; CHECK-NEXT: indirectbr i8* [[RECOVER]], [label %try.cont]
40 lpad: ; preds = %entry
41 %0 = landingpad { i8*, i32 }
43 %1 = extractvalue { i8*, i32 } %0, 0
44 store i8* %1, i8** %exn.slot
45 %2 = extractvalue { i8*, i32 } %0, 1
46 store i32 %2, i32* %ehselector.slot
50 ; CHECK-NOT: @handle_exception()
52 catch: ; preds = %lpad
53 %exn = load i8*, i8** %exn.slot
54 call void @llvm.eh.begincatch(i8* %exn, i8* null) #1
55 call void @handle_exception()
56 call void @llvm.eh.endcatch() #1
59 try.cont: ; preds = %catch, %invoke.cont
65 ; CHECK: define internal i8* @test.catch()
66 ; CHECK: call i8* @llvm.frameaddress(i32 1)
67 ; CHECK: call i8* @llvm.x86.seh.recoverfp(i8* bitcast (void ()* @test to i8*), i8* %{{.*}})
68 ; CHECK: call void @handle_exception()
69 ; CHECK: ret i8* blockaddress(@test, %try.cont)
73 declare void @may_throw() #0
75 declare i32 @__CxxFrameHandler3(...)
77 ; Function Attrs: nounwind
78 declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #1
80 declare void @handle_exception() #0
82 ; Function Attrs: nounwind
83 declare void @llvm.eh.endcatch() #1
85 attributes #0 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
86 attributes #1 = { nounwind }