1*f4a2713aSLionel Sambuc // RUN: not %clang_cc1 -triple i686-pc-linux-gnu %s -o - -emit-llvm -verify | FileCheck %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc typedef __typeof(sizeof(int)) size_t; 4*f4a2713aSLionel Sambuc 5*f4a2713aSLionel Sambuc namespace test1 { 6*f4a2713aSLionel Sambuc struct A { void operator delete(void*,size_t); int x; }; 7*f4a2713aSLionel Sambuc 8*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_ZN5test11aEPNS_1AE( 9*f4a2713aSLionel Sambuc void a(A *x) { 10*f4a2713aSLionel Sambuc // CHECK: load 11*f4a2713aSLionel Sambuc // CHECK-NEXT: icmp eq {{.*}}, null 12*f4a2713aSLionel Sambuc // CHECK-NEXT: br i1 13*f4a2713aSLionel Sambuc // CHECK: call void @_ZN5test11AdlEPvj(i8* %{{.*}}, i32 4) 14*f4a2713aSLionel Sambuc delete x; 15*f4a2713aSLionel Sambuc } 16*f4a2713aSLionel Sambuc } 17*f4a2713aSLionel Sambuc 18*f4a2713aSLionel Sambuc // Check that we make cookies for the two-arg delete even when using 19*f4a2713aSLionel Sambuc // the global allocator and deallocator. 20*f4a2713aSLionel Sambuc namespace test2 { 21*f4a2713aSLionel Sambuc struct A { 22*f4a2713aSLionel Sambuc int x; 23*f4a2713aSLionel Sambuc void *operator new[](size_t); 24*f4a2713aSLionel Sambuc void operator delete[](void *, size_t); 25*f4a2713aSLionel Sambuc }; 26*f4a2713aSLionel Sambuc 27*f4a2713aSLionel Sambuc // CHECK: define [[A:%.*]]* @_ZN5test24testEv() 28*f4a2713aSLionel Sambuc A *test() { 29*f4a2713aSLionel Sambuc // CHECK: [[NEW:%.*]] = call noalias i8* @_Znaj(i32 44) 30*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[NEW]] to i32* 31*f4a2713aSLionel Sambuc // CHECK-NEXT: store i32 10, i32* [[T0]] 32*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[NEW]], i64 4 33*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to [[A]]* 34*f4a2713aSLionel Sambuc // CHECK-NEXT: ret [[A]]* [[T2]] 35*f4a2713aSLionel Sambuc return ::new A[10]; 36*f4a2713aSLionel Sambuc } 37*f4a2713aSLionel Sambuc 38*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_ZN5test24testEPNS_1AE( 39*f4a2713aSLionel Sambuc void test(A *p) { 40*f4a2713aSLionel Sambuc // CHECK: [[P:%.*]] = alloca [[A]]*, align 4 41*f4a2713aSLionel Sambuc // CHECK-NEXT: store [[A]]* {{%.*}}, [[A]]** [[P]], align 4 42*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load [[A]]** [[P]], align 4 43*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = icmp eq [[A]]* [[T0]], null 44*f4a2713aSLionel Sambuc // CHECK-NEXT: br i1 [[T1]], 45*f4a2713aSLionel Sambuc // CHECK: [[T2:%.*]] = bitcast [[A]]* [[T0]] to i8* 46*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 -4 47*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i32* 48*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T5:%.*]] = load i32* [[T4]] 49*f4a2713aSLionel Sambuc // CHECK-NEXT: call void @_ZdaPv(i8* [[T3]]) 50*f4a2713aSLionel Sambuc // CHECK-NEXT: br label 51*f4a2713aSLionel Sambuc ::delete[] p; 52*f4a2713aSLionel Sambuc } 53*f4a2713aSLionel Sambuc } 54*f4a2713aSLionel Sambuc 55*f4a2713aSLionel Sambuc // rdar://problem/8913519 56*f4a2713aSLionel Sambuc namespace test3 { 57*f4a2713aSLionel Sambuc struct A { 58*f4a2713aSLionel Sambuc int x; 59*f4a2713aSLionel Sambuc void operator delete[](void *, size_t); 60*f4a2713aSLionel Sambuc }; 61*f4a2713aSLionel Sambuc struct B : A {}; 62*f4a2713aSLionel Sambuc 63*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_ZN5test34testEv() 64*f4a2713aSLionel Sambuc void test() { 65*f4a2713aSLionel Sambuc // CHECK: call noalias i8* @_Znaj(i32 24) 66*f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 67*f4a2713aSLionel Sambuc // CHECK-NEXT: store i32 5 68*f4a2713aSLionel Sambuc (void) new B[5]; 69*f4a2713aSLionel Sambuc } 70*f4a2713aSLionel Sambuc } 71