[WinEH] Add some test cases I forgot to add to previous commits
[oota-llvm.git] / test / CodeGen / WinEH / cppeh-catch-all-win32.ll
1 ; RUN: opt -winehprepare -S -o - < %s | FileCheck %s
2
3 ; This test is based on the following code:
4 ;
5 ; extern "C" void may_throw();
6 ; extern "C" void handle_exception();
7 ; extern "C" void test() {
8 ;   try {
9 ;     may_throw();
10 ;   } catch (...) {
11 ;     handle_exception();
12 ;   }
13 ; }
14
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"
17
18 ; The function entry in this case remains unchanged.
19 ; CHECK: define void @test()
20 ; CHECK: entry:
21 ; CHECK:   invoke void @may_throw()
22 ; CHECK:           to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
23
24 define void @test() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
25 entry:
26   %exn.slot = alloca i8*
27   %ehselector.slot = alloca i32
28   invoke void @may_throw()
29           to label %invoke.cont unwind label %lpad
30
31 invoke.cont:                                      ; preds = %entry
32   br label %try.cont
33
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]
39
40 lpad:                                             ; preds = %entry
41   %0 = landingpad { i8*, i32 }
42           catch i8* null
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
47   br label %catch
48
49 ; CHECK-NOT: catch:
50 ; CHECK-NOT: @handle_exception()
51
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
57   br label %try.cont
58
59 try.cont:                                         ; preds = %catch, %invoke.cont
60   ret void
61
62 ; CHECK: }
63 }
64
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)
70 ; CHECK: }
71
72
73 declare void @may_throw() #0
74
75 declare i32 @__CxxFrameHandler3(...)
76
77 ; Function Attrs: nounwind
78 declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #1
79
80 declare void @handle_exception() #0
81
82 ; Function Attrs: nounwind
83 declare void @llvm.eh.endcatch() #1
84
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 }