1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NOSIZE
2 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -emit-llvm -o - -Oz -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,CHECK-SIZE
14 // CHECK-LABEL: define{{.*}} void @_Z2t3P1S
16 // CHECK: icmp {{.*}} null
19 // CHECK: call void @_ZdlPv
21 // Check the delete is inside the 'if !null' check unless we're optimizing
22 // for size. FIXME: We could omit the branch entirely in this case.
23 // CHECK-NOSIZE-NEXT: br
24 // CHECK-SIZE-NEXT: ret
34 // CHECK-LABEL: define{{.*}} void @_Z2t4P1T
36 // CHECK: call void @_ZN1TD1Ev
37 // CHECK-SIZE-NEXT: br
38 // CHECK: call void @_ZdlPv
45 public: operator T
*() const;
56 void *operator new(__SIZE_TYPE__ sz
);
57 void operator delete(void *p
) { ::operator delete(p
); }
61 // CHECK-LABEL: define{{.*}} void @_ZN5test04testEPNS_1AE(
63 // CHECK: call void @_ZN5test01AD1Ev
64 // CHECK-SIZE-NEXT: br
65 // CHECK: call void @_ZN5test01AdlEPv
69 // CHECK-LABEL: define linkonce_odr void @_ZN5test01AD1Ev(ptr {{[^,]*}} %this) unnamed_addr
70 // CHECK-LABEL: define linkonce_odr void @_ZN5test01AdlEPv
79 // CHECK-LABEL: define{{.*}} void @_ZN5test14testEPA10_A20_NS_1AE(
80 void test(A (*arr
)[10][20]) {
82 // CHECK: icmp eq ptr [[PTR:%.*]], null
85 // CHECK: [[BEGIN:%.*]] = getelementptr inbounds [10 x [20 x [[A:%.*]]]], ptr [[PTR]], i32 0, i32 0, i32 0
86 // CHECK-NEXT: [[ALLOC:%.*]] = getelementptr inbounds i8, ptr [[BEGIN]], i64 -8
87 // CHECK-NEXT: [[COUNT:%.*]] = load i64, ptr [[ALLOC]]
88 // CHECK: [[END:%.*]] = getelementptr inbounds [[A]], ptr [[BEGIN]], i64 [[COUNT]]
89 // CHECK-NEXT: [[ISEMPTY:%.*]] = icmp eq ptr [[BEGIN]], [[END]]
90 // CHECK-NEXT: br i1 [[ISEMPTY]],
91 // CHECK: [[PAST:%.*]] = phi ptr [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ]
92 // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds [[A]], ptr [[PAST]], i64 -1
93 // CHECK-NEXT: call void @_ZN5test11AD1Ev(ptr {{[^,]*}} [[CUR]])
94 // CHECK-NEXT: [[ISDONE:%.*]] = icmp eq ptr [[CUR]], [[BEGIN]]
95 // CHECK-NEXT: br i1 [[ISDONE]]
96 // CHECK: call void @_ZdaPv(ptr noundef [[ALLOC]])
101 // CHECK-LABEL: define{{.*}} void @_ZN5test21fEPb
103 // CHECK: call void @_ZdlPv(ptr
105 // CHECK: call void @_ZdaPv(ptr
111 void f(int a
[10][20]) {
112 // CHECK: call void @_ZdaPv(ptr
118 // PR10341: ::delete with a virtual destructor
121 void operator delete (void *);
124 // CHECK-LABEL: define{{.*}} void @_ZN5test421global_delete_virtualEPNS_1XE
125 void global_delete_virtual(X
*xp
) {
126 // Load the offset-to-top from the vtable and apply it.
127 // This has to be done first because the dtor can mess it up.
128 // CHECK: [[XP:%.*]] = load ptr, ptr [[XP_ADDR:%.*]]
129 // CHECK: [[VTABLE:%.*]] = load ptr, ptr [[XP]]
130 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds i64, ptr [[VTABLE]], i64 -2
131 // CHECK-NEXT: [[OFFSET:%.*]] = load i64, ptr [[T0]], align 8
132 // CHECK-NEXT: [[ALLOCATED:%.*]] = getelementptr inbounds i8, ptr [[XP]], i64 [[OFFSET]]
133 // Load the complete-object destructor (not the deleting destructor)
134 // and call noundef it.
135 // CHECK-NEXT: [[VTABLE:%.*]] = load ptr, ptr [[XP:%.*]]
136 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds ptr, ptr [[VTABLE]], i64 0
137 // CHECK-NEXT: [[DTOR:%.*]] = load ptr, ptr [[T0]]
138 // CHECK-NEXT: call void [[DTOR]](ptr {{[^,]*}} [[OBJ:%.*]])
139 // Call the global operator delete.
140 // CHECK-NEXT: call void @_ZdlPv(ptr noundef [[ALLOCATED]]) [[NUW:#[0-9]+]]
147 // CHECK-LABEL: define{{.*}} void @_ZN5test523array_delete_incompleteEPNS_10IncompleteES1_
148 void array_delete_incomplete(Incomplete
*p1
, Incomplete
*p2
) {
149 // CHECK: call void @_ZdlPv
151 // CHECK: call void @_ZdaPv
156 // CHECK: attributes [[NUW]] = {{[{].*}} nounwind {{.*[}]}}