From c2548258b9e0a6713ae368888628137b1ac50735 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Mon, 25 Jul 2022 12:46:40 -0700 Subject: [PATCH] Reduce the required alignment of ArenaString from 8 to 4 (#10298) --- src/google/protobuf/arenastring.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/google/protobuf/arenastring.cc b/src/google/protobuf/arenastring.cc index 3887c940a3..af0c9df6bc 100644 --- a/src/google/protobuf/arenastring.cc +++ b/src/google/protobuf/arenastring.cc @@ -50,7 +50,8 @@ namespace internal { namespace { -// Enforce that allocated data aligns to at least 8 bytes, and that +// TaggedStringPtr::Flags uses the lower 2 bits as tags. +// Enforce that allocated data aligns to at least 4 bytes, and that // the alignment of the global const string value does as well. // The alignment guaranteed by `new std::string` depends on both: // - new align = __STDCPP_DEFAULT_NEW_ALIGNMENT__ / max_align_t @@ -64,8 +65,8 @@ constexpr size_t kNewAlign = alignof(std::max_align_t); #endif constexpr size_t kStringAlign = alignof(std::string); -static_assert((kStringAlign > kNewAlign ? kStringAlign : kNewAlign) >= 8, ""); -static_assert(alignof(ExplicitlyConstructedArenaString) >= 8, ""); +static_assert((kStringAlign > kNewAlign ? kStringAlign : kNewAlign) >= 4, ""); +static_assert(alignof(ExplicitlyConstructedArenaString) >= 4, ""); } // namespace