[AMDGPU][True16][CodeGen] true16 codegen pattern for v_med3_u/i16 (#121850)
[llvm-project.git] / clang / test / CodeGenCXX / delete.cpp
blobd5b0dc67129102b06df58a8b78feb6cb84ce0d11
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
4 void t1(int *a) {
5 delete a;
8 struct S {
9 int a;
12 // POD types.
14 // CHECK-LABEL: define{{.*}} void @_Z2t3P1S
15 void t3(S *s) {
16 // CHECK: icmp {{.*}} null
17 // CHECK: br i1
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
25 delete s;
28 // Non-POD
29 struct T {
30 ~T();
31 int a;
34 // CHECK-LABEL: define{{.*}} void @_Z2t4P1T
35 void t4(T *t) {
36 // CHECK: call void @_ZN1TD1Ev
37 // CHECK-SIZE-NEXT: br
38 // CHECK: call void @_ZdlPvm
39 delete t;
42 // PR5102
43 template <typename T>
44 class A {
45 public: operator T *() const;
48 void f() {
49 A<char*> a;
51 delete a;
54 namespace test0 {
55 struct A {
56 void *operator new(__SIZE_TYPE__ sz);
57 void operator delete(void *p) { ::operator delete(p); }
58 ~A() {}
61 // CHECK-LABEL: define{{.*}} void @_ZN5test04testEPNS_1AE(
62 void test(A *a) {
63 // CHECK: call void @_ZN5test01AD1Ev
64 // CHECK-SIZE-NEXT: br
65 // CHECK: call void @_ZN5test01AdlEPv
66 delete a;
69 // CHECK-LABEL: define linkonce_odr void @_ZN5test01AD1Ev(ptr {{[^,]*}} %this) unnamed_addr
70 // CHECK-LABEL: define linkonce_odr void @_ZN5test01AdlEPv
73 namespace test1 {
74 struct A {
75 int x;
76 ~A();
79 // CHECK-LABEL: define{{.*}} void @_ZN5test14testEPA10_A20_NS_1AE(
80 void test(A (*arr)[10][20]) {
81 delete [] arr;
82 // CHECK: icmp eq ptr [[PTR:%.*]], null
83 // CHECK-NEXT: br i1
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]])
102 namespace test2 {
103 // CHECK-LABEL: define{{.*}} void @_ZN5test21fEPb
104 void f(bool *b) {
105 // CHECK: call void @_ZdlPvm(ptr{{.*}}i64
106 delete b;
107 // CHECK: call void @_ZdaPv(ptr
108 delete [] b;
112 namespace test3 {
113 void f(int a[10][20]) {
114 // CHECK: call void @_ZdaPv(ptr
115 delete a;
119 namespace test4 {
120 // PR10341: ::delete with a virtual destructor
121 struct X {
122 virtual ~X();
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]+]]
143 ::delete xp;
147 namespace test5 {
148 struct Incomplete;
149 // CHECK-LABEL: define{{.*}} void @_ZN5test523array_delete_incompleteEPNS_10IncompleteES1_
150 void array_delete_incomplete(Incomplete *p1, Incomplete *p2) {
151 // CHECK: call void @_ZdlPv
152 delete p1;
153 // CHECK: call void @_ZdaPv
154 delete [] p2;
158 // CHECK: attributes [[NUW]] = {{[{].*}} nounwind {{.*[}]}}