diff options
author | Derek Mauro <dmauro@google.com> | 2022-12-21 07:31:39 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-12-21 07:33:17 -0800 |
commit | 6a876051b118c86e8bfa51961270055da5948813 (patch) | |
tree | 6743ba90a11607eb92365ab96073dc95f5770fd3 /absl/base/macros.h | |
parent | 8caa47cfcddbcddd36d22bbab13f4cd9bccbf5c2 (diff) | |
download | abseil-6a876051b118c86e8bfa51961270055da5948813.tar.gz abseil-6a876051b118c86e8bfa51961270055da5948813.tar.bz2 abseil-6a876051b118c86e8bfa51961270055da5948813.zip |
Adds ABSL_UNREACHABLE(), a public symbol to replace ABSL_INTERNAL_UNREACHABLE
ABSL_UNREACHABLE() is an unreachable statement. A program which reaches
one has undefined behavior, and the compiler may optimize accordingly.
The behavior is changed to abort the program in !NDEBUG or
ABSL_OPTION_HARDENED modes.
PiperOrigin-RevId: 496917150
Change-Id: If036b2d9567933fa266fbcd33f3f98c682ad7f41
Diffstat (limited to 'absl/base/macros.h')
-rw-r--r-- | absl/base/macros.h | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/absl/base/macros.h b/absl/base/macros.h index 3e085a91..bbf7494f 100644 --- a/absl/base/macros.h +++ b/absl/base/macros.h @@ -103,17 +103,11 @@ ABSL_NAMESPACE_END // aborts the program in release mode (when NDEBUG is defined). The // implementation should abort the program as quickly as possible and ideally it // should not be possible to ignore the abort request. -#if (ABSL_HAVE_BUILTIN(__builtin_trap) && \ - ABSL_HAVE_BUILTIN(__builtin_unreachable)) || \ - (defined(__GNUC__) && !defined(__clang__)) -#define ABSL_INTERNAL_HARDENING_ABORT() \ - do { \ - __builtin_trap(); \ - __builtin_unreachable(); \ +#define ABSL_INTERNAL_HARDENING_ABORT() \ + do { \ + ABSL_INTERNAL_IMMEDIATE_ABORT_IMPL(); \ + ABSL_INTERNAL_UNREACHABLE_IMPL(); \ } while (false) -#else -#define ABSL_INTERNAL_HARDENING_ABORT() abort() -#endif // ABSL_HARDENING_ASSERT() // @@ -144,15 +138,7 @@ ABSL_NAMESPACE_END #define ABSL_INTERNAL_RETHROW do {} while (false) #endif // ABSL_HAVE_EXCEPTIONS -// `ABSL_INTERNAL_UNREACHABLE` is an unreachable statement. A program which -// reaches one has undefined behavior, and the compiler may optimize -// accordingly. -#if defined(__GNUC__) || ABSL_HAVE_BUILTIN(__builtin_unreachable) -#define ABSL_INTERNAL_UNREACHABLE __builtin_unreachable() -#elif defined(_MSC_VER) -#define ABSL_INTERNAL_UNREACHABLE __assume(0) -#else -#define ABSL_INTERNAL_UNREACHABLE -#endif +// TODO(b/261916195): Replace ABSL_INTERNAL_UNREACHABLE with ABSL_UNREACHABLE(). +#define ABSL_INTERNAL_UNREACHABLE ABSL_UNREACHABLE() #endif // ABSL_BASE_MACROS_H_ |