https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122255
Bug ID: 122255
Summary: Pointer tagging in filesystem::path::_List::_Impl
assumes at least 4-byte alignment
Product: gcc
Version: 15.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
Target: cris-elf
// Clear the lowest two bits from the pointer (i.e. remove the _Type value)
static _Impl* notype(_Impl* p)
{
constexpr uintptr_t mask = ~(uintptr_t)0x3;
return reinterpret_cast<_Impl*>(reinterpret_cast<uintptr_t>(p) & mask);
}
This pointer tagging assumes we have unused low bits in every pointer obtained
from operator new:
void* p = ::operator new(sizeof(_Impl) + n * sizeof(value_type));
The _Impl type is aligned to alignof(path::_Cmpt):
struct path::_List::_Impl
{
using value_type = _Cmpt;
_Impl(int cap) : _M_size(0), _M_capacity(cap) { }
alignas(value_type) int _M_size;
int _M_capacity;
But on cris-elf that has alignment of one.
So we need to increase the alignment of the _Impl objects. These are entirely
internal to the library, so there's no ABI change for any code users deal with.