1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime-has-weak -o - -fobjc-arc-exceptions %s | FileCheck %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc@class Ety; 4*f4a2713aSLionel Sambuc 5*f4a2713aSLionel Sambuc// These first four tests are all PR11732 / rdar://problem/10667070. 6*f4a2713aSLionel Sambuc 7*f4a2713aSLionel Sambucvoid test0_helper(void); 8*f4a2713aSLionel Sambucvoid test0(void) { 9*f4a2713aSLionel Sambuc @try { 10*f4a2713aSLionel Sambuc test0_helper(); 11*f4a2713aSLionel Sambuc } @catch (Ety *e) { 12*f4a2713aSLionel Sambuc } 13*f4a2713aSLionel Sambuc} 14*f4a2713aSLionel Sambuc// CHECK-LABEL: define void @_Z5test0v() 15*f4a2713aSLionel Sambuc// CHECK: [[E:%.*]] = alloca [[ETY:%.*]]*, align 8 16*f4a2713aSLionel Sambuc// CHECK-NEXT: invoke void @_Z12test0_helperv() 17*f4a2713aSLionel Sambuc// CHECK: [[T0:%.*]] = call i8* @objc_begin_catch( 18*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[ETY]]* 19*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = bitcast [[ETY]]* [[T1]] to i8* 20*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retain(i8* [[T2]]) [[NUW:#[0-9]+]] 21*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to [[ETY]]* 22*f4a2713aSLionel Sambuc// CHECK-NEXT: store [[ETY]]* [[T4]], [[ETY]]** [[E]] 23*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = bitcast [[ETY]]** [[E]] to i8** 24*f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_storeStrong(i8** [[T0]], i8* null) [[NUW]] 25*f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_end_catch() [[NUW]] 26*f4a2713aSLionel Sambuc 27*f4a2713aSLionel Sambucvoid test1_helper(void); 28*f4a2713aSLionel Sambucvoid test1(void) { 29*f4a2713aSLionel Sambuc @try { 30*f4a2713aSLionel Sambuc test1_helper(); 31*f4a2713aSLionel Sambuc } @catch (__weak Ety *e) { 32*f4a2713aSLionel Sambuc } 33*f4a2713aSLionel Sambuc} 34*f4a2713aSLionel Sambuc// CHECK-LABEL: define void @_Z5test1v() 35*f4a2713aSLionel Sambuc// CHECK: [[E:%.*]] = alloca [[ETY:%.*]]*, align 8 36*f4a2713aSLionel Sambuc// CHECK-NEXT: invoke void @_Z12test1_helperv() 37*f4a2713aSLionel Sambuc// CHECK: [[T0:%.*]] = call i8* @objc_begin_catch( 38*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[ETY]]* 39*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = bitcast [[ETY]]** [[E]] to i8** 40*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = bitcast [[ETY]]* [[T1]] to i8* 41*f4a2713aSLionel Sambuc// CHECK-NEXT: call i8* @objc_initWeak(i8** [[T2]], i8* [[T3]]) [[NUW]] 42*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = bitcast [[ETY]]** [[E]] to i8** 43*f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_destroyWeak(i8** [[T0]]) [[NUW]] 44*f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_end_catch() [[NUW]] 45*f4a2713aSLionel Sambuc 46*f4a2713aSLionel Sambucvoid test2_helper(void); 47*f4a2713aSLionel Sambucvoid test2(void) { 48*f4a2713aSLionel Sambuc try { 49*f4a2713aSLionel Sambuc test2_helper(); 50*f4a2713aSLionel Sambuc } catch (Ety *e) { 51*f4a2713aSLionel Sambuc } 52*f4a2713aSLionel Sambuc} 53*f4a2713aSLionel Sambuc// CHECK-LABEL: define void @_Z5test2v() 54*f4a2713aSLionel Sambuc// CHECK: [[E:%.*]] = alloca [[ETY:%.*]]*, align 8 55*f4a2713aSLionel Sambuc// CHECK-NEXT: invoke void @_Z12test2_helperv() 56*f4a2713aSLionel Sambuc// CHECK: [[T0:%.*]] = call i8* @__cxa_begin_catch( 57*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[ETY]]* 58*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = bitcast [[ETY]]* [[T1]] to i8* 59*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retain(i8* [[T2]]) [[NUW]] 60*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to [[ETY]]* 61*f4a2713aSLionel Sambuc// CHECK-NEXT: store [[ETY]]* [[T4]], [[ETY]]** [[E]] 62*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = bitcast [[ETY]]** [[E]] to i8** 63*f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_storeStrong(i8** [[T0]], i8* null) [[NUW]] 64*f4a2713aSLionel Sambuc// CHECK-NEXT: call void @__cxa_end_catch() [[NUW]] 65*f4a2713aSLionel Sambuc 66*f4a2713aSLionel Sambucvoid test3_helper(void); 67*f4a2713aSLionel Sambucvoid test3(void) { 68*f4a2713aSLionel Sambuc try { 69*f4a2713aSLionel Sambuc test3_helper(); 70*f4a2713aSLionel Sambuc } catch (Ety * __weak e) { 71*f4a2713aSLionel Sambuc } 72*f4a2713aSLionel Sambuc} 73*f4a2713aSLionel Sambuc// CHECK-LABEL: define void @_Z5test3v() 74*f4a2713aSLionel Sambuc// CHECK: [[E:%.*]] = alloca [[ETY:%.*]]*, align 8 75*f4a2713aSLionel Sambuc// CHECK-NEXT: invoke void @_Z12test3_helperv() 76*f4a2713aSLionel Sambuc// CHECK: [[T0:%.*]] = call i8* @__cxa_begin_catch( 77*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[ETY]]* 78*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = bitcast [[ETY]]** [[E]] to i8** 79*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = bitcast [[ETY]]* [[T1]] to i8* 80*f4a2713aSLionel Sambuc// CHECK-NEXT: call i8* @objc_initWeak(i8** [[T2]], i8* [[T3]]) [[NUW]] 81*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = bitcast [[ETY]]** [[E]] to i8** 82*f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_destroyWeak(i8** [[T0]]) [[NUW]] 83*f4a2713aSLionel Sambuc// CHECK-NEXT: call void @__cxa_end_catch() [[NUW]] 84*f4a2713aSLionel Sambuc 85*f4a2713aSLionel Sambucnamespace test4 { 86*f4a2713aSLionel Sambuc struct A { 87*f4a2713aSLionel Sambuc id single; 88*f4a2713aSLionel Sambuc id array[2][3]; 89*f4a2713aSLionel Sambuc 90*f4a2713aSLionel Sambuc A(); 91*f4a2713aSLionel Sambuc }; 92*f4a2713aSLionel Sambuc 93*f4a2713aSLionel Sambuc A::A() { 94*f4a2713aSLionel Sambuc throw 0; 95*f4a2713aSLionel Sambuc } 96*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_ZN5test41AC2Ev( 97*f4a2713aSLionel Sambuc // CHECK: [[THIS:%.*]] = load [[A:%.*]]** {{%.*}} 98*f4a2713aSLionel Sambuc // Construct single. 99*f4a2713aSLionel Sambuc // CHECK-NEXT: [[SINGLE:%.*]] = getelementptr inbounds [[A]]* [[THIS]], i32 0, i32 0 100*f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* null, i8** [[SINGLE]], align 8 101*f4a2713aSLionel Sambuc // Construct array. 102*f4a2713aSLionel Sambuc // CHECK-NEXT: [[ARRAY:%.*]] = getelementptr inbounds [[A]]* [[THIS]], i32 0, i32 1 103*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = bitcast [2 x [3 x i8*]]* [[ARRAY]] to i8* 104*f4a2713aSLionel Sambuc // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T0]], i8 0, i64 48, i32 8, i1 false) 105*f4a2713aSLionel Sambuc // throw 0; 106*f4a2713aSLionel Sambuc // CHECK: invoke void @__cxa_throw( 107*f4a2713aSLionel Sambuc // Landing pad from throw site: 108*f4a2713aSLionel Sambuc // CHECK: landingpad 109*f4a2713aSLionel Sambuc // - First, destroy all of array. 110*f4a2713aSLionel Sambuc // CHECK: [[ARRAYBEGIN:%.*]] = getelementptr inbounds [2 x [3 x i8*]]* [[ARRAY]], i32 0, i32 0, i32 0 111*f4a2713aSLionel Sambuc // CHECK-NEXT: [[ARRAYEND:%.*]] = getelementptr inbounds i8** [[ARRAYBEGIN]], i64 6 112*f4a2713aSLionel Sambuc // CHECK-NEXT: br label 113*f4a2713aSLionel Sambuc // CHECK: [[AFTER:%.*]] = phi i8** [ [[ARRAYEND]], {{%.*}} ], [ [[ELT:%.*]], {{%.*}} ] 114*f4a2713aSLionel Sambuc // CHECK-NEXT: [[ELT]] = getelementptr inbounds i8** [[AFTER]], i64 -1 115*f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_storeStrong(i8** [[ELT]], i8* null) [[NUW]] 116*f4a2713aSLionel Sambuc // CHECK-NEXT: [[DONE:%.*]] = icmp eq i8** [[ELT]], [[ARRAYBEGIN]] 117*f4a2713aSLionel Sambuc // CHECK-NEXT: br i1 [[DONE]], 118*f4a2713aSLionel Sambuc // - Next, destroy single. 119*f4a2713aSLionel Sambuc // CHECK: call void @objc_storeStrong(i8** [[SINGLE]], i8* null) [[NUW]] 120*f4a2713aSLionel Sambuc // CHECK: br label 121*f4a2713aSLionel Sambuc // CHECK: resume 122*f4a2713aSLionel Sambuc} 123*f4a2713aSLionel Sambuc 124*f4a2713aSLionel Sambuc// CHECK: attributes [[NUW]] = { nounwind } 125