[WinEH] Add some test cases I forgot to add to previous commits
[oota-llvm.git] / test / CodeGen / WinEH / seh-inlined-finally.ll
1 ; RUN: opt -S -winehprepare < %s | FileCheck %s
2
3 ; Check that things work when the mid-level optimizer inlines the finally
4 ; block.
5
6 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
7 target triple = "x86_64-pc-windows-msvc"
8
9 %struct._RTL_CRITICAL_SECTION = type { %struct._RTL_CRITICAL_SECTION_DEBUG*, i32, i32, i8*, i8*, i64 }
10 %struct._RTL_CRITICAL_SECTION_DEBUG = type { i16, i16, %struct._RTL_CRITICAL_SECTION*, %struct._LIST_ENTRY, i32, i32, i32, i16, i16 }
11 %struct._LIST_ENTRY = type { %struct._LIST_ENTRY*, %struct._LIST_ENTRY* }
12
13 declare i32 @puts(i8*)
14 declare void @may_crash()
15 declare i32 @__C_specific_handler(...)
16 declare i8* @llvm.framerecover(i8*, i8*, i32) #1
17 declare i8* @llvm.frameaddress(i32)
18 declare void @llvm.frameescape(...)
19 declare dllimport void @EnterCriticalSection(%struct._RTL_CRITICAL_SECTION*)
20 declare dllimport void @LeaveCriticalSection(%struct._RTL_CRITICAL_SECTION*)
21
22 define void @use_finally() personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) {
23 entry:
24   invoke void @may_crash()
25           to label %invoke.cont unwind label %lpad
26
27 invoke.cont:                                      ; preds = %entry
28   %call.i = tail call i32 @puts(i8* null)
29   ret void
30
31 lpad:                                             ; preds = %entry
32   %0 = landingpad { i8*, i32 }
33           cleanup
34   %call.i2 = tail call i32 @puts(i8* null)
35   resume { i8*, i32 } %0
36 }
37
38 ; CHECK-LABEL: define void @use_finally()
39 ; CHECK: invoke void @may_crash()
40 ;
41 ; CHECK: landingpad
42 ; CHECK-NEXT: cleanup
43 ; CHECK-NEXT: call i8* (...) @llvm.eh.actions(i32 0, void (i8*, i8*)* @use_finally.cleanup)
44 ; CHECK-NEXT: indirectbr i8* %recover, []
45
46 ; Function Attrs: nounwind uwtable
47 define i32 @call_may_crash_locked() personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) {
48 entry:
49   %p = alloca %struct._RTL_CRITICAL_SECTION, align 8
50   call void (...) @llvm.frameescape(%struct._RTL_CRITICAL_SECTION* %p)
51   call void @EnterCriticalSection(%struct._RTL_CRITICAL_SECTION* %p)
52   invoke void @may_crash()
53           to label %invoke.cont unwind label %lpad
54
55 invoke.cont:                                      ; preds = %entry
56   %tmp2 = call i8* @llvm.frameaddress(i32 0)
57   %tmp3 = call i8* @llvm.framerecover(i8* bitcast (i32 ()* @call_may_crash_locked to i8*), i8* %tmp2, i32 0) #2
58   %tmp6 = bitcast i8* %tmp3 to %struct._RTL_CRITICAL_SECTION*
59   call void @LeaveCriticalSection(%struct._RTL_CRITICAL_SECTION* %tmp6)
60   ret i32 42
61
62 lpad:                                             ; preds = %entry
63   %tmp7 = landingpad { i8*, i32 }
64             cleanup
65   %tmp8 = call i8* @llvm.frameaddress(i32 0)
66   %tmp9 = call i8* @llvm.framerecover(i8* bitcast (i32 ()* @call_may_crash_locked to i8*), i8* %tmp8, i32 0)
67   %tmp12 = bitcast i8* %tmp9 to %struct._RTL_CRITICAL_SECTION*
68   call void @LeaveCriticalSection(%struct._RTL_CRITICAL_SECTION* %tmp12)
69   resume { i8*, i32 } %tmp7
70 }
71
72 ; CHECK-LABEL: define i32 @call_may_crash_locked()
73 ; CHECK: invoke void @may_crash()
74 ;
75 ; CHECK: landingpad
76 ; CHECK-NEXT: cleanup
77 ; CHECK-NEXT: call i8* (...) @llvm.eh.actions(i32 0, void (i8*, i8*)* @call_may_crash_locked.cleanup)
78 ; CHECK-NEXT: indirectbr i8* %recover, []
79
80 ; CHECK-LABEL: define internal void @call_may_crash_locked.cleanup(i8*, i8*)
81 ; CHECK: %tmp9 = call i8* @llvm.framerecover(i8* bitcast (i32 ()* @call_may_crash_locked to i8*), i8* %1, i32 0)
82 ; CHECK: %tmp12 = bitcast i8* %tmp9 to %struct._RTL_CRITICAL_SECTION*
83 ; CHECK: call void @LeaveCriticalSection(%struct._RTL_CRITICAL_SECTION* %tmp12)