1 ; RUN: opt -S -winehprepare < %s | FileCheck %s
3 ; Check that things work when the mid-level optimizer inlines the finally
6 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
7 target triple = "x86_64-pc-windows-msvc"
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* }
13 declare i32 @puts(i8*)
14 declare void @may_crash()
15 declare i32 @__C_specific_handler(...)
16 declare i8* @llvm.localrecover(i8*, i8*, i32) #1
17 declare i8* @llvm.localaddress()
18 declare void @llvm.localescape(...)
19 declare dllimport void @EnterCriticalSection(%struct._RTL_CRITICAL_SECTION*)
20 declare dllimport void @LeaveCriticalSection(%struct._RTL_CRITICAL_SECTION*)
22 define void @use_finally() personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) {
24 invoke void @may_crash()
25 to label %invoke.cont unwind label %lpad
27 invoke.cont: ; preds = %entry
28 %call.i = tail call i32 @puts(i8* null)
31 lpad: ; preds = %entry
32 %0 = landingpad { i8*, i32 }
34 %call.i2 = tail call i32 @puts(i8* null)
35 resume { i8*, i32 } %0
38 ; CHECK-LABEL: define void @use_finally()
39 ; CHECK: invoke void @may_crash()
43 ; CHECK-NEXT: call i8* (...) @llvm.eh.actions(i32 0, void (i8*, i8*)* @use_finally.cleanup)
44 ; CHECK-NEXT: indirectbr i8* %recover, []
46 ; Function Attrs: nounwind uwtable
47 define i32 @call_may_crash_locked() personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) {
49 %p = alloca %struct._RTL_CRITICAL_SECTION, align 8
50 call void (...) @llvm.localescape(%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
55 invoke.cont: ; preds = %entry
56 %tmp2 = call i8* @llvm.localaddress()
57 %tmp3 = call i8* @llvm.localrecover(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)
62 lpad: ; preds = %entry
63 %tmp7 = landingpad { i8*, i32 }
65 %tmp8 = call i8* @llvm.localaddress()
66 %tmp9 = call i8* @llvm.localrecover(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
72 ; CHECK-LABEL: define i32 @call_may_crash_locked()
73 ; CHECK: invoke void @may_crash()
77 ; CHECK-NEXT: call i8* (...) @llvm.eh.actions(i32 0, void (i8*, i8*)* @call_may_crash_locked.cleanup)
78 ; CHECK-NEXT: indirectbr i8* %recover, []
80 ; CHECK-LABEL: define internal void @call_may_crash_locked.cleanup(i8*, i8*)
81 ; CHECK: %tmp9 = call i8* @llvm.localrecover(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)