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