1 ; RUN: llc -mtriple=x86_64-windows-gnu %s -o - | FileCheck %s
3 ; Based on this C++ code:
5 ; as() { at = static_cast<int *>(operator new(sizeof(int))); }
6 ; ~as() { operator delete(at); }
15 ; optnone was added to ensure that branch folding and block layout are not
16 ; disturbed. The key thing about this test is that it ends in an empty
17 ; unreachable block, which forces us to scan back across blocks.
20 ; CHECK: callq __cxa_throw
22 ; CHECK: callq _Unwind_Resume
23 ; CHECK-NEXT: # %unreachable
25 ; CHECK-NEXT: .Lfunc_end0:
27 %struct.as = type { ptr }
29 @_ZZ2amiE2au = internal unnamed_addr global %struct.as zeroinitializer, align 8
30 @_ZGVZ2amiE2au = internal global i64 0, align 8
31 @_ZTIi = external constant ptr
33 define dso_local void @_Z2ami(i32 %0) noinline optnone personality ptr @__gxx_personality_seh0 {
35 %1 = load atomic i8, ptr @_ZGVZ2amiE2au acquire, align 8
36 %guard.uninitialized = icmp eq i8 %1, 0
37 br i1 %guard.uninitialized, label %init.check, label %init.end
39 init.check: ; preds = %entry
40 %2 = tail call i32 @__cxa_guard_acquire(ptr nonnull @_ZGVZ2amiE2au)
41 %tobool = icmp eq i32 %2, 0
42 br i1 %tobool, label %init.end, label %init
44 init: ; preds = %init.check
45 %call.i3 = invoke ptr @_Znwy(i64 4)
46 to label %invoke.cont unwind label %lpad
48 invoke.cont: ; preds = %init
49 store ptr %call.i3, ptr @_ZZ2amiE2au, align 8
50 %3 = tail call i32 @atexit(ptr nonnull @__dtor__ZZ2amiE2au)
51 tail call void @__cxa_guard_release(ptr nonnull @_ZGVZ2amiE2au)
54 init.end: ; preds = %init.check, %invoke.cont, %entry
55 %call.i = tail call ptr @_Znwy(i64 4)
56 %exception = tail call ptr @__cxa_allocate_exception(i64 4)
57 store i32 0, ptr %exception, align 16
58 invoke void @__cxa_throw(ptr %exception, ptr @_ZTIi, ptr null)
59 to label %unreachable unwind label %lpad1
62 %4 = landingpad { ptr, i32 }
64 %5 = extractvalue { ptr, i32 } %4, 0
65 %6 = extractvalue { ptr, i32 } %4, 1
66 tail call void @__cxa_guard_abort(ptr nonnull @_ZGVZ2amiE2au)
69 lpad1: ; preds = %init.end
70 %7 = landingpad { ptr, i32 }
72 %8 = extractvalue { ptr, i32 } %7, 0
73 %9 = extractvalue { ptr, i32 } %7, 1
74 tail call void @_ZdlPv(ptr %call.i)
77 eh.resume: ; preds = %lpad1, %lpad
78 %exn.slot.0 = phi ptr [ %8, %lpad1 ], [ %5, %lpad ]
79 %ehselector.slot.0 = phi i32 [ %9, %lpad1 ], [ %6, %lpad ]
80 %lpad.val = insertvalue { ptr, i32 } undef, ptr %exn.slot.0, 0
81 %lpad.val2 = insertvalue { ptr, i32 } %lpad.val, i32 %ehselector.slot.0, 1
82 resume { ptr, i32 } %lpad.val2
84 unreachable: ; preds = %init.end
88 declare dso_local i32 @__cxa_guard_acquire(ptr)
90 declare dso_local i32 @__gxx_personality_seh0(...)
92 declare dso_local void @__dtor__ZZ2amiE2au()
94 declare dso_local i32 @atexit(ptr)
96 declare dso_local void @__cxa_guard_abort(ptr)
98 declare dso_local void @__cxa_guard_release(ptr)
100 declare dso_local ptr @__cxa_allocate_exception(i64)
102 declare dso_local void @__cxa_throw(ptr, ptr, ptr)
104 declare dso_local noalias ptr @_Znwy(i64)
106 declare dso_local void @_ZdlPv(ptr)