Skip to content

Commit

Permalink
Bug 1946733 - Ignore -Walloc-size-larger-than= in `operator new[](not…
Browse files Browse the repository at this point in the history
…hrow)`. 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
  • Loading branch information
kdashg committed Feb 26, 2025
1 parent 08da4ec commit 0062aa2
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions memory/mozalloc/cxxalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 0062aa2

Please sign in to comment.