diff options
author | Abseil Team <absl-team@google.com> | 2024-02-01 05:47:35 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-02-01 05:48:19 -0800 |
commit | a3ee6ce2e6eee06941a1e9479720cecbd898f4ca (patch) | |
tree | b19fc15b6cdde9605db6da74ae2757a4e1322963 | |
parent | 513a6f93997844a931c68506840a2ca9f5485753 (diff) |
Add ABSL_ATTRIBUTE_UNINITIALIZED macros for use with clang and GCC's `uninitialized`
PiperOrigin-RevId: 603344396
Change-Id: I06721246bf205284843065687378c6d905cbf879
-rw-r--r-- | absl/base/attributes.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/absl/base/attributes.h b/absl/base/attributes.h index d4f67a12..373b6d77 100644 --- a/absl/base/attributes.h +++ b/absl/base/attributes.h @@ -871,4 +871,23 @@ #define ABSL_ATTRIBUTE_NO_UNIQUE_ADDRESS #endif +// ABSL_ATTRIBUTE_UNINITIALIZED +// +// GCC and Clang support a flag `-ftrivial-auto-var-init=<option>` (<option> +// can be "zero" or "pattern") that can be used to initialize automatic stack +// variables. Variables with this attribute will be left uninitialized, +// overriding the compiler flag. +// +// See https://clang.llvm.org/docs/AttributeReference.html#uninitialized +// and https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-uninitialized-variable-attribute +#if ABSL_HAVE_CPP_ATTRIBUTE(clang::uninitialized) +#define ABSL_ATTRIBUTE_UNINITIALIZED [[clang::uninitialized]] +#elif ABSL_HAVE_CPP_ATTRIBUTE(gnu::uninitialized) +#define ABSL_ATTRIBUTE_UNINITIALIZED [[gnu::uninitialized]] +#elif ABSL_HAVE_ATTRIBUTE(uninitialized) +#define ABSL_ATTRIBUTE_UNINITIALIZED __attribute__((uninitialized)) +#else +#define ABSL_ATTRIBUTE_UNINITIALIZED +#endif + #endif // ABSL_BASE_ATTRIBUTES_H_ |