Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / delete-two-arg.cpp
blob552634f430a80c32c389f327d61f09c9999d0aee
1 // RUN: %clang_cc1 -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(ptr 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{{.*}} ptr @_ZN5test24testEv()
29 A *test() {
30 // CHECK: [[NEW:%.*]] = call noalias noundef nonnull ptr @_Znaj(i32 noundef 44)
31 // CHECK-NEXT: store i32 10, ptr [[NEW]]
32 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8, ptr [[NEW]], i32 4
33 // CHECK-NEXT: ret ptr [[T1]]
34 return ::new A[10];
37 // CHECK-LABEL: define{{.*}} void @_ZN5test24testEPNS_1AE(
38 void test(A *p) {
39 // CHECK: [[P:%.*]] = alloca ptr, align 4
40 // CHECK-NEXT: store ptr {{%.*}}, ptr [[P]], align 4
41 // CHECK-NEXT: [[T0:%.*]] = load ptr, ptr [[P]], align 4
42 // CHECK-NEXT: [[T1:%.*]] = icmp eq ptr [[T0]], null
43 // CHECK-NEXT: br i1 [[T1]],
44 // CHECK: [[T3:%.*]] = getelementptr inbounds i8, ptr [[T0]], i32 -4
45 // CHECK-NEXT: [[T5:%.*]] = load i32, ptr [[T3]]
46 // CHECK-NEXT: call void @_ZdaPv(ptr noundef [[T3]])
47 // CHECK-NEXT: br label
48 ::delete[] p;
52 namespace test3 {
53 struct A {
54 int x;
55 void operator delete[](void *, size_t);
57 struct B : A {};
59 // CHECK-LABEL: define{{.*}} void @_ZN5test34testEv()
60 void test() {
61 // CHECK: [[CALL:%.*]] = call noalias noundef nonnull ptr @_Znaj(i32 noundef 24)
62 // CHECK-NEXT: store i32 5
63 (void) new B[5];