From 8c800bb08d353c73d7dd68538388cf3bd2bcc6d0 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 7 Sep 2021 06:10:15 -0700 Subject: Export of internal Abseil changes -- 6eac0cc7bca997ee95afd4ec485077ae8fd99333 by Abseil Team : Add comment not to use `ABSL_ATTRIBUTE_PACKED` with `std::atomic`. PiperOrigin-RevId: 395231460 GitOrigin-RevId: 6eac0cc7bca997ee95afd4ec485077ae8fd99333 Change-Id: Ib4e83bed0f313724b309b6278e9e24a6e5fe9b2c --- absl/base/attributes.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'absl/base') diff --git a/absl/base/attributes.h b/absl/base/attributes.h index 52139556..2665d8f3 100644 --- a/absl/base/attributes.h +++ b/absl/base/attributes.h @@ -548,13 +548,19 @@ // ABSL_ATTRIBUTE_PACKED // // Instructs the compiler not to use natural alignment for a tagged data -// structure, but instead to reduce its alignment to 1. This attribute can -// either be applied to members of a structure or to a structure in its -// entirety. Applying this attribute (judiciously) to a structure in its -// entirety to optimize the memory footprint of very commonly-used structs is -// fine. Do not apply this attribute to a structure in its entirety if the -// purpose is to control the offsets of the members in the structure. Instead, -// apply this attribute only to structure members that need it. +// structure, but instead to reduce its alignment to 1. +// +// Therefore, DO NOT APPLY THIS ATTRIBUTE TO STRUCTS CONTAINING ATOMICS. Doing +// so can cause atomic variables to be mis-aligned and silently violate +// atomicity on x86. +// +// This attribute can either be applied to members of a structure or to a +// structure in its entirety. Applying this attribute (judiciously) to a +// structure in its entirety to optimize the memory footprint of very +// commonly-used structs is fine. Do not apply this attribute to a structure in +// its entirety if the purpose is to control the offsets of the members in the +// structure. Instead, apply this attribute only to structure members that need +// it. // // When applying ABSL_ATTRIBUTE_PACKED only to specific structure members the // natural alignment of structure members not annotated is preserved. Aligned -- cgit v1.2.3