2010-09-02 17:58:18 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -emit-llvm -o - | FileCheck %s
|
2009-08-17 05:13:42 +08:00
|
|
|
|
|
|
|
void t1(int *a) {
|
|
|
|
delete a;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct S {
|
|
|
|
int a;
|
|
|
|
};
|
|
|
|
|
|
|
|
// POD types.
|
|
|
|
void t3(S *s) {
|
|
|
|
delete s;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Non-POD
|
|
|
|
struct T {
|
|
|
|
~T();
|
|
|
|
int a;
|
|
|
|
};
|
|
|
|
|
2010-04-20 10:18:25 +08:00
|
|
|
// CHECK: define void @_Z2t4P1T
|
2009-08-17 05:13:42 +08:00
|
|
|
void t4(T *t) {
|
2010-04-20 10:18:25 +08:00
|
|
|
// CHECK: call void @_ZN1TD1Ev
|
|
|
|
// CHECK-NEXT: bitcast
|
|
|
|
// CHECK-NEXT: call void @_ZdlPv
|
2009-08-17 05:13:42 +08:00
|
|
|
delete t;
|
|
|
|
}
|
2009-10-01 13:49:51 +08:00
|
|
|
|
|
|
|
// PR5102
|
|
|
|
template <typename T>
|
|
|
|
class A {
|
|
|
|
operator T *() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
void f() {
|
|
|
|
A<char*> a;
|
|
|
|
|
|
|
|
delete a;
|
|
|
|
}
|
2010-04-20 10:18:25 +08:00
|
|
|
|
|
|
|
namespace test0 {
|
|
|
|
struct A {
|
|
|
|
void *operator new(__SIZE_TYPE__ sz);
|
|
|
|
void operator delete(void *p) { ::operator delete(p); }
|
|
|
|
~A() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
// CHECK: define void @_ZN5test04testEPNS_1AE(
|
|
|
|
void test(A *a) {
|
|
|
|
// CHECK: call void @_ZN5test01AD1Ev
|
|
|
|
// CHECK-NEXT: bitcast
|
|
|
|
// CHECK-NEXT: call void @_ZN5test01AdlEPv
|
|
|
|
delete a;
|
|
|
|
}
|
|
|
|
|
2011-07-10 01:41:47 +08:00
|
|
|
// CHECK: define linkonce_odr void @_ZN5test01AD1Ev(%"struct.test0::A"* %this) unnamed_addr
|
2010-04-20 10:18:25 +08:00
|
|
|
// CHECK: define linkonce_odr void @_ZN5test01AdlEPv
|
|
|
|
}
|
2010-09-02 17:58:18 +08:00
|
|
|
|
|
|
|
namespace test1 {
|
|
|
|
struct A {
|
|
|
|
int x;
|
|
|
|
~A();
|
|
|
|
};
|
|
|
|
|
|
|
|
// CHECK: define void @_ZN5test14testEPA10_A20_NS_1AE(
|
|
|
|
void test(A (*arr)[10][20]) {
|
|
|
|
delete [] arr;
|
2011-07-13 09:41:37 +08:00
|
|
|
// CHECK: icmp eq [10 x [20 x [[A:%.*]]]]* [[PTR:%.*]], null
|
2010-09-02 17:58:18 +08:00
|
|
|
// CHECK-NEXT: br i1
|
|
|
|
|
2011-07-13 09:41:37 +08:00
|
|
|
// CHECK: [[BEGIN:%.*]] = getelementptr inbounds [10 x [20 x [[A]]]]* [[PTR]], i32 0, i32 0, i32 0
|
|
|
|
// CHECK-NEXT: [[T0:%.*]] = bitcast [[A]]* [[BEGIN]] to i8*
|
|
|
|
// CHECK-NEXT: [[ALLOC:%.*]] = getelementptr inbounds i8* [[T0]], i64 -8
|
|
|
|
// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[ALLOC]] to i64*
|
|
|
|
// CHECK-NEXT: [[COUNT:%.*]] = load i64* [[T1]]
|
|
|
|
// CHECK: [[END:%.*]] = getelementptr inbounds [[A]]* [[BEGIN]], i64 [[COUNT]]
|
2011-07-13 16:09:46 +08:00
|
|
|
// CHECK-NEXT: [[ISEMPTY:%.*]] = icmp eq [[A]]* [[BEGIN]], [[END]]
|
|
|
|
// CHECK-NEXT: br i1 [[ISEMPTY]],
|
2011-07-13 09:41:37 +08:00
|
|
|
// CHECK: [[PAST:%.*]] = phi [[A]]* [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ]
|
|
|
|
// CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds [[A]]* [[PAST]], i64 -1
|
|
|
|
// CHECK-NEXT: call void @_ZN5test11AD1Ev([[A]]* [[CUR]])
|
|
|
|
// CHECK-NEXT: [[ISDONE:%.*]] = icmp eq [[A]]* [[CUR]], [[BEGIN]]
|
|
|
|
// CHECK-NEXT: br i1 [[ISDONE]]
|
2010-09-02 17:58:18 +08:00
|
|
|
// CHECK: call void @_ZdaPv(i8* [[ALLOC]])
|
|
|
|
}
|
|
|
|
}
|
2010-09-02 23:34:35 +08:00
|
|
|
|
|
|
|
namespace test2 {
|
|
|
|
// CHECK: define void @_ZN5test21fEPb
|
|
|
|
void f(bool *b) {
|
|
|
|
// CHECK: call void @_ZdlPv(i8*
|
|
|
|
delete b;
|
|
|
|
// CHECK: call void @_ZdaPv(i8*
|
|
|
|
delete [] b;
|
|
|
|
}
|
|
|
|
}
|
2010-09-14 04:15:54 +08:00
|
|
|
|
|
|
|
namespace test3 {
|
|
|
|
void f(int a[10][20]) {
|
|
|
|
// CHECK: call void @_ZdaPv(i8*
|
|
|
|
delete a;
|
|
|
|
}
|
|
|
|
}
|
2011-07-13 08:54:47 +08:00
|
|
|
|
|
|
|
namespace test4 {
|
|
|
|
// PR10341: ::delete with a virtual destructor
|
|
|
|
struct X {
|
|
|
|
virtual ~X();
|
|
|
|
void operator delete (void *);
|
|
|
|
};
|
|
|
|
|
|
|
|
// CHECK: define void @_ZN5test421global_delete_virtualEPNS_1XE
|
|
|
|
void global_delete_virtual(X *xp) {
|
|
|
|
// CHECK: [[VTABLE:%.*]] = load void ([[X:%.*]])***
|
|
|
|
// CHECK-NEXT: [[VFN:%.*]] = getelementptr inbounds void ([[X]])** [[VTABLE]], i64 0
|
|
|
|
// CHECK-NEXT: [[VFNPTR:%.*]] = load void ([[X]])** [[VFN]]
|
|
|
|
// CHECK-NEXT: call void [[VFNPTR]]([[X]] [[OBJ:%.*]])
|
|
|
|
// CHECK-NEXT: [[OBJVOID:%.*]] = bitcast [[X]] [[OBJ]] to i8*
|
|
|
|
// CHECK-NEXT: call void @_ZdlPv(i8* [[OBJVOID]]) nounwind
|
|
|
|
::delete xp;
|
|
|
|
}
|
|
|
|
}
|
2011-07-28 02:54:57 +08:00
|
|
|
|
|
|
|
namespace test5 {
|
|
|
|
struct Incomplete;
|
|
|
|
// CHECK: define void @_ZN5test523array_delete_incompleteEPNS_10IncompleteE
|
|
|
|
void array_delete_incomplete(Incomplete *p) {
|
|
|
|
// CHECK: call void @_ZdlPv
|
|
|
|
delete [] p;
|
|
|
|
}
|
|
|
|
}
|