]> 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>
Tue, 8 Jul 2025 20:48:15 +0000 (21:48 +0100)
commitac2fb60a67d6d1de6446c25c5623b8a1389f4770
tree583f93dad706985db631191df4b72b8b343f94e4
parent7d11ae1dd95a0296eeb5c14bfe3a5d4ec8873e3b
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.

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>
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]