[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGenCXX / delete-two-arg.cpp
blobf9d504c24a64ca51c58b19b7b2f257bb19f59662
1 // RUN: %clang_cc1 -no-opaque-pointers -triple i686-pc-linux-gnu %s -o - -emit-llvm -verify | FileCheck %s
2 // expected-no-diagnostics
4 typedef __typeof(sizeof(int)) size_t;
6 namespace test1 {
7 struct A { void operator delete(void*,size_t); int x; };
9 // CHECK-LABEL: define{{.*}} void @_ZN5test11aEPNS_1AE(
10 void a(A *x) {
11 // CHECK: load
12 // CHECK-NEXT: icmp eq {{.*}}, null
13 // CHECK-NEXT: br i1
14 // CHECK: call void @_ZN5test11AdlEPvj(i8* noundef %{{.*}}, i32 noundef 4)
15 delete x;
19 // Check that we make cookies for the two-arg delete even when using
20 // the global allocator and deallocator.
21 namespace test2 {
22 struct A {
23 int x;
24 void *operator new[](size_t);
25 void operator delete[](void *, size_t);
28 // CHECK: define{{.*}} [[A:%.*]]* @_ZN5test24testEv()
29 A *test() {
30 // CHECK: [[NEW:%.*]] = call noalias noundef nonnull i8* @_Znaj(i32 noundef 44)
31 // CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[NEW]] to i32*
32 // CHECK-NEXT: store i32 10, i32* [[T0]]
33 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8, i8* [[NEW]], i32 4
34 // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to [[A]]*
35 // CHECK-NEXT: ret [[A]]* [[T2]]
36 return ::new A[10];
39 // CHECK-LABEL: define{{.*}} void @_ZN5test24testEPNS_1AE(
40 void test(A *p) {
41 // CHECK: [[P:%.*]] = alloca [[A]]*, align 4
42 // CHECK-NEXT: store [[A]]* {{%.*}}, [[A]]** [[P]], align 4
43 // CHECK-NEXT: [[T0:%.*]] = load [[A]]*, [[A]]** [[P]], align 4
44 // CHECK-NEXT: [[T1:%.*]] = icmp eq [[A]]* [[T0]], null
45 // CHECK-NEXT: br i1 [[T1]],
46 // CHECK: [[T2:%.*]] = bitcast [[A]]* [[T0]] to i8*
47 // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8, i8* [[T2]], i32 -4
48 // CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i32*
49 // CHECK-NEXT: [[T5:%.*]] = load i32, i32* [[T4]]
50 // CHECK-NEXT: call void @_ZdaPv(i8* noundef [[T3]])
51 // CHECK-NEXT: br label
52 ::delete[] p;
56 // rdar://problem/8913519
57 namespace test3 {
58 struct A {
59 int x;
60 void operator delete[](void *, size_t);
62 struct B : A {};
64 // CHECK-LABEL: define{{.*}} void @_ZN5test34testEv()
65 void test() {
66 // CHECK: [[CALL:%.*]] = call noalias noundef nonnull i8* @_Znaj(i32 noundef 24)
67 // CHECK-NEXT: bitcast i8* [[CALL]] to i32*
68 // CHECK-NEXT: store i32 5
69 (void) new B[5];