Skip to content

Commit aad15c0

Browse files
ezbrcopybara-github
authored andcommitted
Assume that control bytes don't alias CommonFields.
PiperOrigin-RevId: 778538667 Change-Id: Ibcd7433923f88726cc83afd9bf09604bf3979eeb
1 parent ddbb517 commit aad15c0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

absl/container/internal/raw_hash_set.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,14 @@ class CommonFields : public CommonFieldsGenerationInfo {
964964

965965
ctrl_t* control() const {
966966
ABSL_SWISSTABLE_ASSERT(capacity() > 0);
967-
ABSL_SWISSTABLE_IGNORE_UNINITIALIZED_RETURN(heap_or_soo_.control().get());
967+
// Assume that the control bytes don't alias `this`.
968+
ctrl_t* ctrl = heap_or_soo_.control().get();
969+
[[maybe_unused]] size_t num_control_bytes = NumControlBytes(capacity());
970+
ABSL_ASSUME(reinterpret_cast<uintptr_t>(ctrl + num_control_bytes) <=
971+
reinterpret_cast<uintptr_t>(this) ||
972+
reinterpret_cast<uintptr_t>(this + 1) <=
973+
reinterpret_cast<uintptr_t>(ctrl));
974+
ABSL_SWISSTABLE_IGNORE_UNINITIALIZED_RETURN(ctrl);
968975
}
969976

970977
void set_control(ctrl_t* c) { heap_or_soo_.control().set(c); }

0 commit comments

Comments
 (0)