https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99845

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #1)
>     allocbuf(uint32_t nelems) {
>         return new(std::nothrow) T[static_cast<size_t>(nelems)];
>     }
> 
> expands to
> 
> <<cleanup_point return <retval> = TARGET_EXPR <D.7342, SAVE_EXPR <(sizetype)
> nelems> <= 1152921504606846975 ? (size_t) ((SAVE_EXPR <(sizetype) nelems> +
> 1) * 8) : (size_t) __cxa_throw_bad_array_new_length ()>;, TARGET_EXPR
> <D.7341, MyType::operator new [] (NON_LVALUE_EXPR <D.7342>, (const struct
> nothrow_t &) &nothrow)>;;, *(sizetype *) NON_LVALUE_EXPR <D.7341> =
> SAVE_EXPR <(sizetype) nelems>;, try
>   {
> ...
> 
> which calls MyType::operator new[] and then stores 'nelems' at the beginning
> of the allocated storage for some reason (ABI?).

Yes
https://itanium-cxx-abi.github.io/cxx-abi/abi.html#array-cookies
(not just ABI but also for the reason the ABI talks about).

> 
> That makes using new[] (std::nothrow) "unsafe" to call it seems?

I guess for the nothrow versions we should wrap that nelems store into a
COND_EXPR based on whether operator new returned non-NULL.

Reply via email to