Skip to content

Commit

Permalink
Statically assert pointer alignment.
Browse files Browse the repository at this point in the history
We use the lower bits for tagging.

PiperOrigin-RevId: 619606723
  • Loading branch information
ckennelly authored and copybara-github committed Mar 27, 2024
1 parent 2693af9 commit 9b2b61c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/google/protobuf/arenastring.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ class PROTOBUF_EXPORT TaggedStringPtr {

private:
static inline void assert_aligned(const void* p) {
static_assert(kMask <= alignof(void*), "Pointer underaligned for bit mask");
static_assert(kMask <= alignof(std::string),
"std::string underaligned for bit mask");
ABSL_DCHECK_EQ(reinterpret_cast<uintptr_t>(p) & kMask, 0UL);
}

Expand Down

0 comments on commit 9b2b61c

Please sign in to comment.