Bug 1946733 - Ignore -Walloc-size-larger-than= in operator new[](nothrow). r=firefox-build-system-reviewers,sergesanspaille,sylvestre

Unfortunately, GCC-14 appears to be generating this warning due to its own
frontend/codegen [interactions?].

This is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85783, which was
WONTFIX'd. Comment #3 admits:
> The excessive constant argument is introduced by the C++ front-end, in
> cp/build_operator_new_call(), which emits a call to operator new[](size_t).
> The code was added in r190546 as a solution to prevent unsigned wrapping
> (when array new expression must compute the amount of space to allocate as a
> product of the number of elements and element size).  When the replacement
> operator new[] is inlined the excessive argument is propagated to malloc()
> and ultimately triggers the warning.

Differential Revision: https://phabricator.services.mozilla.com/D239424
This commit is contained in:
Kelsey Gilbert
2025-02-26 12:18:20 +00:00
parent 13d09c1f65
commit 0b76d798ac

View File

@@ -42,9 +42,22 @@ MOZALLOC_EXPORT_NEW void* operator new[](size_t size) noexcept(false) {
return moz_xmalloc(size);
}
// Inlining `new` like this is technically against C++ spec, but we crave perf.
MOZALLOC_EXPORT_NEW void* operator new[](size_t size,
const std::nothrow_t&) noexcept(true) {
#ifdef __GNUC__
// GCC-14 codegen at -O2 causes false positive due to converting
// `new A[n]` to `malloc(-1)` when `n > PTRDIFF_MAX/sizeof(A)`.
// (See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85783, WONTFIX'd)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Walloc-size-larger-than="
#endif
return malloc_impl(size);
#ifdef __GNUC__
# pragma GCC diagnostic pop
#endif
}
MOZALLOC_EXPORT_NEW void operator delete(void* ptr) noexcept(true) {