[Bug libstdc++/108951] std::valarray doesn't support extended alignment

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Oct 27 09:55:28 GMT 2025


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

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:38a441689b0d4f3e9a712e3dde4d4fe8db474520

commit r16-4646-g38a441689b0d4f3e9a712e3dde4d4fe8db474520
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Oct 24 12:56:04 2025 +0100

    libstdc++: Make std::valarray support overaligned types [PR108951]

    Switch std::valarray<T> memory allocation to use std::__new_allocator<T>
    to allocate and deallocate memory. This adds support for extended
    alignment types without needing to duplicate all the logic from
    __new_allocator::allocate and __new_allocator::dellocate.

    std::__new_allocator is used instead of std::allocator because we want
    to ensure that the memory is still allocated with operator new, so we
    don't want to use any possible program-defined specialization of
    std::allocator<T> which the user might have provided.

    To make using an allocator possible, __valarray_release_memory needs to
    become a function template so that it knows the type T. It also needs an
    additional parameter specifying the size of the allocation.

    This change doesn't cause an ABI change for types with fundamental
    alignment, because __new_allocator still uses the same operator delete
    function (or the sized version, which is ABI compatible) to free the
    memory. So if memory for a valarray is allocated in one translation unit
    and deallocated in another, and those TUs are compiled with different
    versions of GCC, we still get memory from the same operator new and
    release it with the same operator delete (or the compatibled sized
    version). For types with extended alignment this does potentially cause
    an ABI change on targets where the aligned version of operator delete
    doesn't just call free(p), but support for extended alignment types was
    previously just broken and had undefined behaviour.

    libstdc++-v3/ChangeLog:

            PR libstdc++/108951
            * include/bits/valarray_array.h( __valarray_get_storage): Use
            std::__new_allocator.
            (__valarray_release_memory): Likewise.
            * include/std/valarray: Pass _M_size to
            __valarray_release_memory.
            * testsuite/26_numerics/valarray/108951.cc: New test.

    Reviewed-by: Tomasz KamiÅski <tkaminsk@redhat.com>


More information about the Gcc-bugs mailing list