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

            Bug ID: 118681
           Summary: [C++17] unsynchronized_pool_resource may fail to
                    respect alignment
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dieram3 at gmail dot com
  Target Milestone: ---

`(un)synchronized_pool_resource` fails to respect requested alignment in
certain scenarios. Here's a Godbolt repro:

https://godbolt.org/z/YKsv4a469

The problem seems to be that the implementation assumes a chunk of blocks of
size B can satisfy any alignment A such as A <= B. That is not true, since this
depends on the highest power of 2 factor in B. For example, a chunk of blocks
of size 24 cannot provide blocks aligned to 16 bytes. Even if the first block
was at address 0x0, the second block would be at address 0x16 and thus
unaligned. The max alignment blocks of size 24 can satisfy is 8 (the largest
power of 2).

Reply via email to