1 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify %s
2 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
3 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify %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
12 typedef decltype(sizeof(0)) size_t;
13 enum class align_val_t : std::size_t {};
18 void *operator new(std::size_t __sz, const std::nothrow_t&) noexcept;
19 void *operator new[](std::size_t __sz, const std::nothrow_t&) noexcept;
21 void *operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) noexcept;
22 void *operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) noexcept;
23 void operator delete(void *, std::align_val_t, const std::nothrow_t&);
24 void operator delete[](void *, std::align_val_t, const std::nothrow_t&);
25 void operator delete(void*, std::size_t, std::align_val_t) noexcept;
26 void operator delete[](void*, std::size_t, std::align_val_t) noexcept;
28 void *operator new(std::size_t, std::align_val_t, long long);
30 struct alignas(256) OveralignedS {
41 p = new (std::nothrow) S;
45 pa = new (std::nothrow) S[4];
48 void testOveraligned() {
49 auto *p = new OveralignedS;
50 p = new ((std::align_val_t)8) OveralignedS;
52 p = new (std::nothrow) OveralignedS;
54 auto *pa = new OveralignedS[4];
55 pa = new ((std::align_val_t)8) OveralignedS[4];
57 pa = new (std::nothrow) OveralignedS[4];
58 // No error here since it is not calling a replaceable allocation function.
59 p = new ((std::align_val_t)8, 10LL) OveralignedS;
63 // expected-no-diagnostics
65 // expected-error@-16 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on}}
66 // expected-note@-17 {{if you supply your own aligned allocation functions}}
67 // expected-error@-18 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
68 // expected-note@-19 {{if you supply your own aligned allocation functions}}
70 // expected-error@-20 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on}}
71 // expected-note@-21 {{if you supply your own aligned allocation functions}}
72 // expected-error@-22 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
73 // expected-note@-23 {{if you supply your own aligned allocation functions}}
75 // expected-error@-24 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
76 // expected-note@-25 {{if you supply your own aligned allocation functions}}
78 // expected-error@-26 {{aligned allocation function of type 'void *(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept' is only available on}}
79 // expected-note@-27 {{if you supply your own aligned allocation functions}}
80 // expected-error@-28 {{aligned deallocation function of type 'void (void *, std::align_val_t, const std::nothrow_t &) noexcept' is only available on}}
81 // expected-note@-29 {{if you supply your own aligned allocation functions}}
83 // expected-error@-29 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on}}
84 // expected-note@-30 {{if you supply your own aligned allocation functions}}
85 // expected-error@-31 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
86 // expected-note@-32 {{if you supply your own aligned allocation functions}}
88 // expected-error@-33 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on}}
89 // expected-note@-34 {{if you supply your own aligned allocation functions}}
90 // expected-error@-35 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
91 // expected-note@-36 {{if you supply your own aligned allocation functions}}
93 // expected-error@-37 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
94 // expected-note@-38 {{if you supply your own aligned allocation functions}}
96 // expected-error@-39 {{aligned allocation function of type 'void *(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept' is only available on}}
97 // expected-note@-40 {{if you supply your own aligned allocation functions}}
98 // expected-error@-41 {{aligned deallocation function of type 'void (void *, std::align_val_t, const std::nothrow_t &) noexcept' is only available on}}
99 // expected-note@-42 {{if you supply your own aligned allocation functions}}
103 void testOveralignedCheckOS() {
104 auto *p = new OveralignedS;
108 // expected-no-diagnostics
111 // expected-error@-7 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on iOS 11 or newer}}
112 // expected-error@-8 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on iOS 11 or newer}}}
114 // expected-error@-10 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on tvOS 11 or newer}}}
115 // expected-error@-11 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on tvOS 11 or newer}}}
116 #elif defined(WATCHOS)
117 // expected-error@-13 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on watchOS 4 or newer}}}
118 // expected-error@-14 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on watchOS 4 or newer}}}
120 // expected-error@-16 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on macOS 10.14 or newer}}}
121 // expected-error@-17 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on macOS 10.14 or newer}}}
124 // expected-note@-20 2 {{if you supply your own aligned allocation functions}}
127 // Test that diagnostics are produced when an unavailable aligned deallocation
128 // function is called from a deleting destructor.
129 struct alignas(256) OveralignedS2 {
131 virtual ~OveralignedS2();
134 OveralignedS2::~OveralignedS2() {}
137 // expected-no-diagnostics
140 // expected-error@-6 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on iOS 11 or newer}}}
141 // expected-note@-7 {{if you supply your own aligned allocation functions}}
143 // expected-error@-9 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on tvOS 11 or newer}}}
144 // expected-note@-10 {{if you supply your own aligned allocation functions}}
145 #elif defined(WATCHOS)
146 // expected-error@-12 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on watchOS 4 or newer}}}
147 // expected-note@-13 {{if you supply your own aligned allocation functions}}
149 // expected-error@-15 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on macOS 10.14 or newer}}}
150 // expected-note@-16 {{if you supply your own aligned allocation functions}}
154 void testExplicitOperatorNewDelete() {
155 void *p = operator new(128);
157 p = operator new[](128);
158 operator delete[](p);
159 p = __builtin_operator_new(128);
160 __builtin_operator_delete(p);
163 void testExplicitOperatorNewDeleteOveraligned() {
164 void *p = operator new(128, (std::align_val_t)64);
165 operator delete(p, (std::align_val_t)64);
166 p = operator new[](128, (std::align_val_t)64);
167 operator delete[](p, (std::align_val_t)64);
168 p = __builtin_operator_new(128, (std::align_val_t)64);
169 __builtin_operator_delete(p, (std::align_val_t)64);
173 // expected-no-diagnostics
175 // expected-error@-11 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on}}
176 // expected-note@-12 {{if you supply your own aligned allocation functions}}
178 // expected-error@-13 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
179 // expected-note@-14 {{if you supply your own aligned allocation functions}}
181 // expected-error@-15 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on}}
182 // expected-note@-16 {{if you supply your own aligned allocation functions}}
184 // expected-error@-17 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
185 // expected-note@-18 {{if you supply your own aligned allocation functions}}
187 // expected-error@-19 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on}}
188 // expected-note@-20 {{if you supply your own aligned allocation functions}}
190 // expected-error@-21 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
191 // expected-note@-22 {{if you supply your own aligned allocation functions}}
194 // No errors if user-defined aligned allocation functions are available.
195 void *operator new(std::size_t __sz, std::align_val_t) {
196 static char array[256];
200 void operator delete(void *p, std::align_val_t) {
203 void testOveraligned2() {
204 auto p = new ((std::align_val_t)8) OveralignedS;