1 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DMACOS %s
2 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
3 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify -DMACOS %s
4 // RUN: %clang_cc1 -triple arm64-apple-ios10.0.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DIOS %s
5 // RUN: %clang_cc1 -triple arm64-apple-ios10.0.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
6 // RUN: %clang_cc1 -triple arm64-apple-tvos10.0.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DTVOS %s
7 // RUN: %clang_cc1 -triple arm64-apple-tvos10.0.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
8 // RUN: %clang_cc1 -triple armv7k-apple-watchos3.0.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DWATCHOS %s
9 // RUN: %clang_cc1 -triple armv7k-apple-watchos3.0.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
10 // RUN: %clang_cc1 -triple s390x-none-zos -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DZOS %s
11 // RUN: %clang_cc1 -triple s390x-none-zos -fexceptions -std=c++1z -verify -DNO_ERRORS %s
12 // RUN: %clang_cc1 -triple s390x-none-zos -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify -DZOS %s
15 typedef decltype(sizeof(0)) size_t;
16 enum class align_val_t
: std::size_t {};
21 void *operator new(std::size_t __sz
, const std::nothrow_t
&) noexcept
;
22 void *operator new[](std::size_t __sz
, const std::nothrow_t
&) noexcept
;
24 void *operator new(std::size_t __sz
, std::align_val_t
, const std::nothrow_t
&) noexcept
;
25 void *operator new[](std::size_t __sz
, std::align_val_t
, const std::nothrow_t
&) noexcept
;
26 void operator delete(void *, std::align_val_t
, const std::nothrow_t
&);
27 void operator delete[](void *, std::align_val_t
, const std::nothrow_t
&);
28 void operator delete(void*, std::size_t, std::align_val_t
) noexcept
;
29 void operator delete[](void*, std::size_t, std::align_val_t
) noexcept
;
31 void *operator new(std::size_t, std::align_val_t
, long long);
33 struct alignas(256) OveralignedS
{
44 p
= new (std::nothrow
) S
;
48 pa
= new (std::nothrow
) S
[4];
51 void testOveraligned() {
52 auto *p
= new OveralignedS
;
53 p
= new ((std::align_val_t
)8) OveralignedS
;
55 p
= new (std::nothrow
) OveralignedS
;
57 auto *pa
= new OveralignedS
[4];
58 pa
= new ((std::align_val_t
)8) OveralignedS
[4];
60 pa
= new (std::nothrow
) OveralignedS
[4];
61 // No error here since it is not calling a replaceable allocation function.
62 p
= new ((std::align_val_t
)8, 10LL) OveralignedS
;
66 // expected-no-diagnostics
68 // expected-error-re@-16 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is {{only|not}} available on}}
69 // expected-note@-17 {{if you supply your own aligned allocation functions}}
70 // expected-error-re@-18 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
71 // expected-note@-19 {{if you supply your own aligned allocation functions}}
73 // expected-error-re@-20 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is {{only|not}} available on}}
74 // expected-note@-21 {{if you supply your own aligned allocation functions}}
75 // expected-error-re@-22 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
76 // expected-note@-23 {{if you supply your own aligned allocation functions}}
78 // expected-error-re@-24 {{aligned deallocation function of type 'void (void *, std::size_t, std::align_val_t) noexcept' is {{only|not}} available on}}
79 // expected-note@-25 {{if you supply your own aligned allocation functions}}
81 // expected-error-re@-26 {{aligned allocation function of type 'void *(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept' is {{only|not}} available on}}
82 // expected-note@-27 {{if you supply your own aligned allocation functions}}
83 // expected-error-re@-28 {{aligned deallocation function of type 'void (void *, std::align_val_t, const std::nothrow_t &) noexcept' is {{only|not}} available on}}
84 // expected-note@-29 {{if you supply your own aligned allocation functions}}
86 // expected-error-re@-29 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is {{only|not}} available on}}
87 // expected-note@-30 {{if you supply your own aligned allocation functions}}
88 // expected-error-re@-31 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
89 // expected-note@-32 {{if you supply your own aligned allocation functions}}
91 // expected-error-re@-33 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is {{only|not}} available on}}
92 // expected-note@-34 {{if you supply your own aligned allocation functions}}
93 // expected-error-re@-35 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
94 // expected-note@-36 {{if you supply your own aligned allocation functions}}
96 // expected-error-re@-37 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
97 // expected-note@-38 {{if you supply your own aligned allocation functions}}
99 // expected-error-re@-39 {{aligned allocation function of type 'void *(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept' is {{only|not}} available on}}
100 // expected-note@-40 {{if you supply your own aligned allocation functions}}
101 // expected-error-re@-41 {{aligned deallocation function of type 'void (void *, std::align_val_t, const std::nothrow_t &) noexcept' is {{only|not}} available on}}
102 // expected-note@-42 {{if you supply your own aligned allocation functions}}
106 void testOveralignedCheckOS() {
107 auto *p
= new OveralignedS
;
111 // expected-no-diagnostics
114 // expected-error@-7 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on iOS 11 or newer}}
115 // expected-error@-8 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on iOS 11 or newer}}}
117 // expected-error@-10 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on tvOS 11 or newer}}}
118 // expected-error@-11 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on tvOS 11 or newer}}}
119 #elif defined(WATCHOS)
120 // expected-error@-13 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on watchOS 4 or newer}}}
121 // expected-error@-14 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on watchOS 4 or newer}}}
123 // expected-error@-16 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on macOS 10.13 or newer}}}
124 // expected-error@-17 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on macOS 10.13 or newer}}}
126 // expected-error@-19 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is not available on z/OS}}}
127 // expected-error@-20 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is not available on z/OS}}}
130 // expected-note@-23 2 {{if you supply your own aligned allocation functions}}
133 // Test that diagnostics are produced when an unavailable aligned deallocation
134 // function is called from a deleting destructor.
135 struct alignas(256) OveralignedS2
{
137 virtual ~OveralignedS2();
140 OveralignedS2::~OveralignedS2() {}
143 // expected-no-diagnostics
146 // expected-error@-6 {{aligned deallocation function of type 'void (void *, std::size_t, std::align_val_t) noexcept' is only available on iOS 11 or newer}}}
147 // expected-note@-7 {{if you supply your own aligned allocation functions}}
149 // expected-error@-9 {{aligned deallocation function of type 'void (void *, std::size_t, std::align_val_t) noexcept' is only available on tvOS 11 or newer}}}
150 // expected-note@-10 {{if you supply your own aligned allocation functions}}
151 #elif defined(WATCHOS)
152 // expected-error@-12 {{aligned deallocation function of type 'void (void *, std::size_t, std::align_val_t) noexcept' is only available on watchOS 4 or newer}}}
153 // expected-note@-13 {{if you supply your own aligned allocation functions}}
155 // expected-error@-15 {{aligned deallocation function of type 'void (void *, std::size_t, std::align_val_t) noexcept' is only available on macOS 10.13 or newer}}}
156 // expected-note@-16 {{if you supply your own aligned allocation functions}}
158 // expected-error@-18 {{aligned deallocation function of type 'void (void *, std::size_t, std::align_val_t) noexcept' is not available on z/OS}}}
159 // expected-note@-19 {{if you supply your own aligned allocation functions}}
163 void testExplicitOperatorNewDelete() {
164 void *p
= operator new(128);
166 p
= operator new[](128);
167 operator delete[](p
);
168 p
= __builtin_operator_new(128);
169 __builtin_operator_delete(p
);
172 void testExplicitOperatorNewDeleteOveraligned() {
173 void *p
= operator new(128, (std::align_val_t
)64);
174 operator delete(p
, (std::align_val_t
)64);
175 p
= operator new[](128, (std::align_val_t
)64);
176 operator delete[](p
, (std::align_val_t
)64);
177 p
= __builtin_operator_new(128, (std::align_val_t
)64);
178 __builtin_operator_delete(p
, (std::align_val_t
)64);
182 // expected-no-diagnostics
184 // expected-error-re@-11 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is {{only|not}} available on}}
185 // expected-note@-12 {{if you supply your own aligned allocation functions}}
187 // expected-error-re@-13 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
188 // expected-note@-14 {{if you supply your own aligned allocation functions}}
190 // expected-error-re@-15 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is {{only|not}} available on}}
191 // expected-note@-16 {{if you supply your own aligned allocation functions}}
193 // expected-error-re@-17 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
194 // expected-note@-18 {{if you supply your own aligned allocation functions}}
196 // expected-error-re@-19 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is {{only|not}} available on}}
197 // expected-note@-20 {{if you supply your own aligned allocation functions}}
199 // expected-error-re@-21 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
200 // expected-note@-22 {{if you supply your own aligned allocation functions}}
203 // No errors if user-defined aligned allocation functions are available.
204 void *operator new(std::size_t __sz
, std::align_val_t
) {
205 static char array
[256];
209 void operator delete(void *p
, std::align_val_t
) {
212 void operator delete(void *p
, std::size_t __sz
, std::align_val_t
) {
215 void testOveraligned2() {
216 auto p
= new ((std::align_val_t
)8) OveralignedS
;