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 @_ZdlPvm
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 @_ZdlPvm
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: [[MUL:%.*]] = mul i64 4, [[COUNT]]
97 // CHECK-NEXT: [[SIZE:%.*]] = add i64 [[MUL]], 8
98 // CHECK-NEXT: call void @_ZdaPvm(ptr noundef [[ALLOC]], i64 noundef [[SIZE]])
103 // CHECK-LABEL: define{{.*}} void @_ZN5test21fEPb
105 // CHECK: call void @_ZdlPvm(ptr{{.*}}i64
107 // CHECK: call void @_ZdaPv(ptr
113 void f(int a
[10][20]) {
114 // CHECK: call void @_ZdaPv(ptr
120 // PR10341: ::delete with a virtual destructor
123 void operator delete (void *);
126 // CHECK-LABEL: define{{.*}} void @_ZN5test421global_delete_virtualEPNS_1XE
127 void global_delete_virtual(X
*xp
) {
128 // Load the offset-to-top from the vtable and apply it.
129 // This has to be done first because the dtor can mess it up.
130 // CHECK: [[XP:%.*]] = load ptr, ptr [[XP_ADDR:%.*]]
131 // CHECK: [[VTABLE:%.*]] = load ptr, ptr [[XP]]
132 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds i64, ptr [[VTABLE]], i64 -2
133 // CHECK-NEXT: [[OFFSET:%.*]] = load i64, ptr [[T0]], align 8
134 // CHECK-NEXT: [[ALLOCATED:%.*]] = getelementptr inbounds i8, ptr [[XP]], i64 [[OFFSET]]
135 // Load the complete-object destructor (not the deleting destructor)
136 // and call noundef it.
137 // CHECK-NEXT: [[VTABLE:%.*]] = load ptr, ptr [[XP:%.*]]
138 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds ptr, ptr [[VTABLE]], i64 0
139 // CHECK-NEXT: [[DTOR:%.*]] = load ptr, ptr [[T0]]
140 // CHECK-NEXT: call void [[DTOR]](ptr {{[^,]*}} [[OBJ:%.*]])
141 // Call the global operator delete.
142 // CHECK-NEXT: call void @_ZdlPvm(ptr noundef [[ALLOCATED]], i64 noundef 8) [[NUW:#[0-9]+]]
149 // CHECK-LABEL: define{{.*}} void @_ZN5test523array_delete_incompleteEPNS_10IncompleteES1_
150 void array_delete_incomplete(Incomplete
*p1
, Incomplete
*p2
) {
151 // CHECK: call void @_ZdlPv
153 // CHECK: call void @_ZdaPv
158 // CHECK: attributes [[NUW]] = {{[{].*}} nounwind {{.*[}]}}