John McCall | 1e7fe75 | 2010-09-02 09:58:18 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -emit-llvm -o - | FileCheck %s |
Anders Carlsson | 60e282c | 2009-08-16 21:13:42 +0000 | [diff] [blame] | 2 | |
| 3 | void t1(int *a) { |
| 4 | delete a; |
| 5 | } |
| 6 | |
| 7 | struct S { |
| 8 | int a; |
| 9 | }; |
| 10 | |
| 11 | // POD types. |
| 12 | void t3(S *s) { |
| 13 | delete s; |
| 14 | } |
| 15 | |
| 16 | // Non-POD |
| 17 | struct T { |
| 18 | ~T(); |
| 19 | int a; |
| 20 | }; |
| 21 | |
John McCall | 9c82afc | 2010-04-20 02:18:25 +0000 | [diff] [blame] | 22 | // CHECK: define void @_Z2t4P1T |
Anders Carlsson | 60e282c | 2009-08-16 21:13:42 +0000 | [diff] [blame] | 23 | void t4(T *t) { |
John McCall | 9c82afc | 2010-04-20 02:18:25 +0000 | [diff] [blame] | 24 | // CHECK: call void @_ZN1TD1Ev |
| 25 | // CHECK-NEXT: bitcast |
| 26 | // CHECK-NEXT: call void @_ZdlPv |
Anders Carlsson | 60e282c | 2009-08-16 21:13:42 +0000 | [diff] [blame] | 27 | delete t; |
| 28 | } |
Douglas Gregor | d69dd78 | 2009-10-01 05:49:51 +0000 | [diff] [blame] | 29 | |
| 30 | // PR5102 |
| 31 | template <typename T> |
| 32 | class A { |
| 33 | operator T *() const; |
| 34 | }; |
| 35 | |
| 36 | void f() { |
| 37 | A<char*> a; |
| 38 | |
| 39 | delete a; |
| 40 | } |
John McCall | 9c82afc | 2010-04-20 02:18:25 +0000 | [diff] [blame] | 41 | |
| 42 | namespace test0 { |
| 43 | struct A { |
| 44 | void *operator new(__SIZE_TYPE__ sz); |
| 45 | void operator delete(void *p) { ::operator delete(p); } |
| 46 | ~A() {} |
| 47 | }; |
| 48 | |
| 49 | // CHECK: define void @_ZN5test04testEPNS_1AE( |
| 50 | void test(A *a) { |
| 51 | // CHECK: call void @_ZN5test01AD1Ev |
| 52 | // CHECK-NEXT: bitcast |
| 53 | // CHECK-NEXT: call void @_ZN5test01AdlEPv |
| 54 | delete a; |
| 55 | } |
| 56 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 57 | // CHECK: define linkonce_odr void @_ZN5test01AD1Ev(%"struct.test0::A"* %this) unnamed_addr |
John McCall | 9c82afc | 2010-04-20 02:18:25 +0000 | [diff] [blame] | 58 | // CHECK: define linkonce_odr void @_ZN5test01AdlEPv |
| 59 | } |
John McCall | 1e7fe75 | 2010-09-02 09:58:18 +0000 | [diff] [blame] | 60 | |
| 61 | namespace test1 { |
| 62 | struct A { |
| 63 | int x; |
| 64 | ~A(); |
| 65 | }; |
| 66 | |
| 67 | // CHECK: define void @_ZN5test14testEPA10_A20_NS_1AE( |
| 68 | void test(A (*arr)[10][20]) { |
| 69 | delete [] arr; |
John McCall | 7cfd76c | 2011-07-13 01:41:37 +0000 | [diff] [blame^] | 70 | // CHECK: icmp eq [10 x [20 x [[A:%.*]]]]* [[PTR:%.*]], null |
John McCall | 1e7fe75 | 2010-09-02 09:58:18 +0000 | [diff] [blame] | 71 | // CHECK-NEXT: br i1 |
| 72 | |
John McCall | 7cfd76c | 2011-07-13 01:41:37 +0000 | [diff] [blame^] | 73 | // CHECK: [[BEGIN:%.*]] = getelementptr inbounds [10 x [20 x [[A]]]]* [[PTR]], i32 0, i32 0, i32 0 |
| 74 | // CHECK-NEXT: [[T0:%.*]] = bitcast [[A]]* [[BEGIN]] to i8* |
| 75 | // CHECK-NEXT: [[ALLOC:%.*]] = getelementptr inbounds i8* [[T0]], i64 -8 |
| 76 | // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[ALLOC]] to i64* |
| 77 | // CHECK-NEXT: [[COUNT:%.*]] = load i64* [[T1]] |
| 78 | // CHECK-NEXT: [[ISZERO:%.*]] = icmp eq i64 [[COUNT]], 0 |
| 79 | // CHECK-NEXT: br i1 [[ISZERO]], |
| 80 | // CHECK: [[END:%.*]] = getelementptr inbounds [[A]]* [[BEGIN]], i64 [[COUNT]] |
John McCall | 1e7fe75 | 2010-09-02 09:58:18 +0000 | [diff] [blame] | 81 | // CHECK-NEXT: br label |
John McCall | 7cfd76c | 2011-07-13 01:41:37 +0000 | [diff] [blame^] | 82 | // CHECK: [[PAST:%.*]] = phi [[A]]* [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ] |
| 83 | // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds [[A]]* [[PAST]], i64 -1 |
| 84 | // CHECK-NEXT: call void @_ZN5test11AD1Ev([[A]]* [[CUR]]) |
| 85 | // CHECK-NEXT: [[ISDONE:%.*]] = icmp eq [[A]]* [[CUR]], [[BEGIN]] |
| 86 | // CHECK-NEXT: br i1 [[ISDONE]] |
John McCall | 1e7fe75 | 2010-09-02 09:58:18 +0000 | [diff] [blame] | 87 | // CHECK: call void @_ZdaPv(i8* [[ALLOC]]) |
| 88 | } |
| 89 | } |
Douglas Gregor | f9cce31 | 2010-09-02 15:34:35 +0000 | [diff] [blame] | 90 | |
| 91 | namespace test2 { |
| 92 | // CHECK: define void @_ZN5test21fEPb |
| 93 | void f(bool *b) { |
| 94 | // CHECK: call void @_ZdlPv(i8* |
| 95 | delete b; |
| 96 | // CHECK: call void @_ZdaPv(i8* |
| 97 | delete [] b; |
| 98 | } |
| 99 | } |
Argyrios Kyrtzidis | 4076dac | 2010-09-13 20:15:54 +0000 | [diff] [blame] | 100 | |
| 101 | namespace test3 { |
| 102 | void f(int a[10][20]) { |
| 103 | // CHECK: call void @_ZdaPv(i8* |
| 104 | delete a; |
| 105 | } |
| 106 | } |
Douglas Gregor | a8b20f7 | 2011-07-13 00:54:47 +0000 | [diff] [blame] | 107 | |
| 108 | namespace test4 { |
| 109 | // PR10341: ::delete with a virtual destructor |
| 110 | struct X { |
| 111 | virtual ~X(); |
| 112 | void operator delete (void *); |
| 113 | }; |
| 114 | |
| 115 | // CHECK: define void @_ZN5test421global_delete_virtualEPNS_1XE |
| 116 | void global_delete_virtual(X *xp) { |
| 117 | // CHECK: [[VTABLE:%.*]] = load void ([[X:%.*]])*** |
| 118 | // CHECK-NEXT: [[VFN:%.*]] = getelementptr inbounds void ([[X]])** [[VTABLE]], i64 0 |
| 119 | // CHECK-NEXT: [[VFNPTR:%.*]] = load void ([[X]])** [[VFN]] |
| 120 | // CHECK-NEXT: call void [[VFNPTR]]([[X]] [[OBJ:%.*]]) |
| 121 | // CHECK-NEXT: [[OBJVOID:%.*]] = bitcast [[X]] [[OBJ]] to i8* |
| 122 | // CHECK-NEXT: call void @_ZdlPv(i8* [[OBJVOID]]) nounwind |
| 123 | ::delete xp; |
| 124 | } |
| 125 | } |