You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix false positive where warnings were asserted for placement new even
when no additional space is requested
The PlacementNewChecker incorrectly triggered warnings when the storage
provided matched or exceeded the allocated type size, causing false
positives. Now the warning triggers only when the provided storage is
strictly less than the required size.
Add test cases covering exact size, undersize, and oversize scenarios to
validate the fix.
Fixesllvm#149240
::new (buffer1) S[N]; //expected-warning{{Storage provided to placement new is only 64 bytes, whereas the allocated array type requires more space for internal needs}} expected-note 1 {{}}
190
+
alignas(S) unsignedchar buffer1[sizeof(S) * N];
191
+
::new (buffer1) S[N]; //no-warning: See comments above
173
192
}
174
193
175
194
voidf2() {
176
195
structS {
177
196
short a;
178
197
};
179
198
180
-
// maybe ok but we need to warn.
199
+
// On some systems, placement array new could allocate more memory than the nominal size of the array.
200
+
// See the comment at f1() above for more details.
::new (buffer2) S[N]; //expected-warning{{68 bytes is possibly not enough for array allocation which requires 64 bytes. Current overhead requires the size of 4 bytes}} expected-note 1 {{}}
202
+
alignas(S) unsignedchar buffer2[sizeof(S) * N + sizeof(int)];
203
+
::new (buffer2) S[N]; //no-warning: See comments above
0 commit comments