Moving WinEH outlining tests to an architecture neutral location
[oota-llvm.git] / test / CodeGen / WinEH / cppeh-catch-all.ll
1 ; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
2
3 ; This test is based on the following code:
4 ;
5 ; void test()
6 ; {
7 ;   try {
8 ;     may_throw();
9 ;   } catch (...) {
10 ;     handle_exception();
11 ;   }
12 ; }
13 ;
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.
16
17 ; ModuleID = 'catch-all.cpp'
18 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
19 target triple = "x86_64-pc-windows-msvc"
20
21 ; Function Attrs: uwtable
22 define void @_Z4testv() #0 {
23 entry:
24   %exn.slot = alloca i8*
25   %ehselector.slot = alloca i32
26   invoke void @_Z9may_throwv()
27           to label %invoke.cont unwind label %lpad
28
29 invoke.cont:                                      ; preds = %entry
30   br label %try.cont
31
32 lpad:                                             ; preds = %entry
33   %tmp = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
34           catch i8* null
35   %tmp1 = extractvalue { i8*, i32 } %tmp, 0
36   store i8* %tmp1, i8** %exn.slot
37   %tmp2 = extractvalue { i8*, i32 } %tmp, 1
38   store i32 %tmp2, i32* %ehselector.slot
39   br label %catch
40
41 catch:                                            ; preds = %lpad
42   %exn = load i8*, i8** %exn.slot
43   call void @llvm.eh.begincatch(i8* %exn, i8* null) #2
44   call void @_Z16handle_exceptionv()
45   br label %invoke.cont2
46
47 invoke.cont2:                                     ; preds = %catch
48   call void @llvm.eh.endcatch()
49   br label %try.cont
50
51 try.cont:                                         ; preds = %invoke.cont2, %invoke.cont
52   ret void
53 }
54
55 ; CHECK: define internal i8* @_Z4testv.catch(i8*, i8*) {
56 ; CHECK: entry:
57 ; CHECK:   %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)
58 ; CHECK:   %eh.data = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*
59 ; CHECK:   %eh.obj.ptr = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 1
60 ; CHECK:   %eh.obj = load i8*, i8** %eh.obj.ptr
61 ; CHECK:   call void @_Z16handle_exceptionv()
62 ; CHECK:   ret i8* blockaddress(@_Z4testv, %try.cont)
63 ; CHECK: }
64
65 declare void @_Z9may_throwv() #1
66
67 declare i32 @__CxxFrameHandler3(...)
68
69 declare void @llvm.eh.begincatch(i8*, i8*)
70
71 declare void @_Z16handle_exceptionv() #1
72
73 declare void @llvm.eh.endcatch()
74
75 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" }
76 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" }
77 attributes #2 = { noinline noreturn nounwind }
78 attributes #3 = { nounwind }
79 attributes #4 = { noreturn nounwind }
80
81 !llvm.ident = !{!0}
82
83 !0 = !{!"clang version 3.7.0 (trunk 226027)"}