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