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

--- Comment #14 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Jonathan Wakely
<[email protected]>:

https://gcc.gnu.org/g:87990a0603b0f118b34895008ef7bfbb6f049398

commit r14-12155-g87990a0603b0f118b34895008ef7bfbb6f049398
Author: Jonathan Wakely <[email protected]>
Date:   Fri Jul 4 16:44:13 2025 +0100

    libstdc++: Ensure pool resources meet alignment requirements [PR118681]

    For allocations with size > alignment and size % alignment != 0 we were
    sometimes returning pointers that did not meet the requested aligment.
    For example, allocate(24, 16) would select the pool for 24-byte objects
    and the second allocation from that pool (at offset 24 bytes into the
    pool) is only 8-byte aligned not 16-byte aligned.

    The pool resources need to round up the requested allocation size to a
    multiple of the alignment, so that the selected pool will always return
    allocations that meet the alignment requirement.

    This backport includes the fixes for the bootstrap error and the tests.

    libstdc++-v3/ChangeLog:

            PR libstdc++/118681
            * src/c++17/memory_resource.cc (choose_block_size): New
            function.
            (synchronized_pool_resource::do_allocate): Use choose_block_size
            to determine appropriate block size.
            (synchronized_pool_resource::do_deallocate): Likewise
            (unsynchronized_pool_resource::do_allocate): Likewise.
            (unsynchronized_pool_resource::do_deallocate): Likewise
            * testsuite/20_util/synchronized_pool_resource/118681.cc: New
            test.
            * testsuite/20_util/unsynchronized_pool_resource/118681.cc: New
            test.

    Reviewed-by: Tomasz KamiÅski <[email protected]>

    (cherry picked from commit ac2fb60a67d6d1de6446c25c5623b8a1389f4770)

Reply via email to