Skip to content

Commit 8c800bb

Browse files
Abseil Teamdinord
authored andcommitted
Export of internal Abseil changes
-- 6eac0cc7bca997ee95afd4ec485077ae8fd99333 by Abseil Team <[email protected]>: Add comment not to use `ABSL_ATTRIBUTE_PACKED` with `std::atomic`. PiperOrigin-RevId: 395231460 GitOrigin-RevId: 6eac0cc7bca997ee95afd4ec485077ae8fd99333 Change-Id: Ib4e83bed0f313724b309b6278e9e24a6e5fe9b2c
1 parent 6039dd9 commit 8c800bb

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

absl/base/attributes.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,19 @@
548548
// ABSL_ATTRIBUTE_PACKED
549549
//
550550
// Instructs the compiler not to use natural alignment for a tagged data
551-
// structure, but instead to reduce its alignment to 1. This attribute can
552-
// either be applied to members of a structure or to a structure in its
553-
// entirety. Applying this attribute (judiciously) to a structure in its
554-
// entirety to optimize the memory footprint of very commonly-used structs is
555-
// fine. Do not apply this attribute to a structure in its entirety if the
556-
// purpose is to control the offsets of the members in the structure. Instead,
557-
// apply this attribute only to structure members that need it.
551+
// structure, but instead to reduce its alignment to 1.
552+
//
553+
// Therefore, DO NOT APPLY THIS ATTRIBUTE TO STRUCTS CONTAINING ATOMICS. Doing
554+
// so can cause atomic variables to be mis-aligned and silently violate
555+
// atomicity on x86.
556+
//
557+
// This attribute can either be applied to members of a structure or to a
558+
// structure in its entirety. Applying this attribute (judiciously) to a
559+
// structure in its entirety to optimize the memory footprint of very
560+
// commonly-used structs is fine. Do not apply this attribute to a structure in
561+
// its entirety if the purpose is to control the offsets of the members in the
562+
// structure. Instead, apply this attribute only to structure members that need
563+
// it.
558564
//
559565
// When applying ABSL_ATTRIBUTE_PACKED only to specific structure members the
560566
// natural alignment of structure members not annotated is preserved. Aligned

0 commit comments

Comments
 (0)