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

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

https://gcc.gnu.org/g:1b18a9e53960f34f40ed6e2f0f9320269bbafba6

commit r16-4422-g1b18a9e53960f34f40ed6e2f0f9320269bbafba6
Author: Jonathan Wakely <[email protected]>
Date:   Sat Oct 11 11:22:38 2025 +0100

    libstdc++: Ensure filesystem::path internals are sufficiently aligned
[PR122255]

    We need the memory allocated for a path::_List::_Impl to be at least
    4-byte aligned, so that we can use the two least significant bits to
    store a _Type value. Use __STDCPP_DEFAULT_NEW_ALIGNMENT__ to check that
    in a static_assert. Also add a static_assert to check the memory will be
    aligned suitably for the _Impl object itself. In practice both
    assertions should pass as long as operator new guarantees to return
    memory with at least 4-byte alignment, which seems to be true for malloc
    on GCC's supported targets.

    Allocation of path::_List::_Impl objects is refactored into a new
    _Impl::create function so that the memory allocation is done in one
    place, rather than being repeated in path::_List::_Impl::copy and
    path::_List::reserve. If we late decide to use aligned-new to support
    targets that fail the new static assertions we won't need to do that in
    two different places. Calling operator delete already only happens in
    one place, the _Impl_deleter.

    The create function is actually implemented in terms of another new
    function, create_unchecked. The overflow checks in create aren't needed
    when copying an existing object, because we already checked its size
    doesn't overflow.

    Destroying the components is now done by a destructor, which the
    _Impl_deleter invokes.

    libstdc++-v3/ChangeLog:

            PR libstdc++/122255
            * src/c++17/fs_path.cc (path::_List::_Impl::~_Impl): Define
            destructor.
            (path::_List::_Impl::copy): Use create_unchecked.
            (path::_List::_Impl): Add static assertions.
            (path::_List::_Impl::create): New static member function.
            (path::_List::_Impl::create_unchecked): Likewise.
            (path::_List::_Impl_deleter::operator()): Use destructor.
            (path::_List::reserve): Use create.

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

Reply via email to