Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / ubsan-new-checks.cpp
blob352f56b734de6d21889df0531c581a648a71f72e
1 // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -S -emit-llvm -fsanitize=alignment %s -o - | FileCheck %s
3 struct alignas(32) S1 {
4 int x;
5 S1();
6 };
8 struct alignas(32) S2 {
9 int x;
12 struct alignas(32) S3 {
13 int x;
14 S3(int *p = new int[4]);
17 struct S4 : public S3 {
18 S4() : S3() {}
21 typedef __attribute__((ext_vector_type(8), aligned(32))) float float32x8_t;
23 struct S5 {
24 float32x8_t x;
27 void *operator new (unsigned long, void *p) { return p; }
28 void *operator new[] (unsigned long, void *p) { return p; }
30 S1 *func_01() {
31 // CHECK-LABEL: define {{.*}} @_Z7func_01v
32 // CHECK: and i64 %{{.*}}, 31, !nosanitize
33 // CHECK: icmp eq i64 %{{.*}}, 0, !nosanitize
34 // CHECK: call void @_ZN2S1C1Ev(
35 // CHECK-NOT: and i64 %{{.*}}, 31
36 // CHECK: ret ptr
37 return new S1[20];
40 S2 *func_02() {
41 // CHECK-LABEL: define {{.*}} @_Z7func_02v
42 // CHECK: and i64 %{{.*}}, 31, !nosanitize
43 // CHECK: icmp eq i64 %{{.*}}, 0, !nosanitize
44 // CHECK: ret ptr
45 return new S2;
48 S2 *func_03() {
49 // CHECK-LABEL: define {{.*}} @_Z7func_03v
50 // CHECK: and i64 %{{.*}}, 31, !nosanitize
51 // CHECK: icmp eq i64 %{{.*}}, 0, !nosanitize
52 // CHECK-NOT: and i64 %{{.*}}, 31
53 // CHECK: ret ptr
54 return new S2[20];
57 float32x8_t *func_04() {
58 // CHECK-LABEL: define {{.*}} @_Z7func_04v
59 // CHECK: and i64 %{{.*}}, 31, !nosanitize
60 // CHECK: icmp eq i64 %{{.*}}, 0, !nosanitize
61 // CHECK: ret ptr
62 return new float32x8_t;
65 float32x8_t *func_05() {
66 // CHECK-LABEL: define {{.*}} @_Z7func_05v
67 // CHECK: and i64 %{{.*}}, 31, !nosanitize
68 // CHECK: icmp eq i64 %{{.*}}, 0, !nosanitize
69 // CHECK-NOT: and i64 %{{.*}}, 31
70 // CHECK: ret ptr
71 return new float32x8_t[20];
74 S3 *func_07() {
75 // CHECK-LABEL: define {{.*}} @_Z7func_07v
76 // CHECK: and i64 %{{.*}}, 31, !nosanitize
77 // CHECK: icmp eq i64 %{{.*}}, 0, !nosanitize
78 // CHECK: and i64 %{{.*}}, 3, !nosanitize
79 // CHECK: icmp eq i64 %{{.*}}, 0, !nosanitize
80 // CHECK: ret ptr
81 return new S3;
84 S3 *func_08() {
85 // CHECK-LABEL: define {{.*}} @_Z7func_08v
86 // CHECK: and i64 %{{.*}}, 31, !nosanitize
87 // CHECK: icmp eq i64 %{{.*}}, 0, !nosanitize
88 // CHECK: and i64 %{{.*}}, 3, !nosanitize
89 // CHECK: icmp eq i64 %{{.*}}, 0, !nosanitize
90 // CHECK: ret ptr
91 return new S3[10];
95 S2 *func_10(void *p) {
96 // CHECK-LABEL: define {{.*}} @_Z7func_10Pv
97 // CHECK: and i64 %{{.*}}, 31, !nosanitize
98 // CHECK: icmp eq i64 %{{.*}}, 0, !nosanitize
99 // CHECK: ret ptr
100 return new(p) S2;
103 S2 *func_11(void *p) {
104 // CHECK-LABEL: define {{.*}} @_Z7func_11Pv
105 // CHECK: and i64 %{{.*}}, 31, !nosanitize
106 // CHECK: icmp eq i64 %{{.*}}, 0, !nosanitize
107 // CHECK-NOT: and i64 %{{.*}}, 31, !nosanitize
108 // CHECK-NOT: icmp eq i64 %{{.*}}, 0, !nosanitize
109 // CHECK: ret ptr
110 return new(p) S2[10];
113 float32x8_t *func_12() {
114 // CHECK-LABEL: define {{.*}} @_Z7func_12v
115 // CHECK: and i64 %{{.*}}, 31, !nosanitize
116 // CHECK: icmp eq i64 %{{.*}}, 0, !nosanitize
117 // CHECK: ret ptr
118 return new float32x8_t;
121 float32x8_t *func_13() {
122 // CHECK-LABEL: define {{.*}} @_Z7func_13v
123 // CHECK: and i64 %{{.*}}, 31, !nosanitize
124 // CHECK: icmp eq i64 %{{.*}}, 0, !nosanitize
125 // CHECK-NOT: and i64 %{{.*}}, 31
126 // CHECK: ret ptr
127 return new float32x8_t[20];
130 S4 *func_14() {
131 // CHECK-LABEL: define {{.*}} @_Z7func_14v
132 // CHECK: and i64 %{{.*}}, 31, !nosanitize
133 // CHECK: icmp eq i64 %{{.*}}, 0, !nosanitize
134 // CHECK-NOT: and i64 %{{.*}}, 31
135 // CHECK: ret ptr
136 return new S4;
139 S5 *func_15(const S5 *ptr) {
140 // CHECK-LABEL: define {{.*}} @_Z7func_15PK2S5
141 // CHECK: and i64 %{{.*}}, 31, !nosanitize
142 // CHECK: icmp eq i64 %{{.*}}, 0, !nosanitize
143 // CHECK-NOT: and i64
144 // CHECK: ret ptr
145 return new S5(*ptr);