]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Ensure pool resources meet alignment requirements [PR118681]
authorJonathan Wakely <jwakely@redhat.com>
Fri, 4 Jul 2025 15:44:13 +0000 (16:44 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 11 Jul 2025 08:38:06 +0000 (09:38 +0100)
commit2de64a64b41989682dcdc621fd72fe107fec8b95
treefb393d9ddf49dc8fe7724ff105fdbfa54c34c3ad
parent6f06b5201bbfce6c1abf8fb0d9a9a0b6ede60186
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 <tkaminsk@redhat.com>
(cherry picked from commit ac2fb60a67d6d1de6446c25c5623b8a1389f4770)
libstdc++-v3/src/c++17/memory_resource.cc
libstdc++-v3/testsuite/20_util/synchronized_pool_resource/118681.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/unsynchronized_pool_resource/118681.cc [new file with mode: 0644]