Correctly define ABSL_UNREACHABLE when Abseil Hardened Fast is enabled Currently, when Abseil Hardened Fast is set and NDEBUG is set, ABSL_UNREACHABLE performs undefined behavior, as the assert is a no-op and the various ABSL_UNREACHABLE_IMPLs can in fact be reached, violating assumptions we have told the compiler to make. PiperOrigin-RevId: 866148746 Change-Id: I4fcad9681d167c40be082521c3bebd9fc27109dc
diff --git a/absl/base/optimization.h b/absl/base/optimization.h index 04678c4..b561128 100644 --- a/absl/base/optimization.h +++ b/absl/base/optimization.h
@@ -222,7 +222,7 @@ // `ABSL_UNREACHABLE()` is an unreachable statement. A program which reaches // one has undefined behavior, and the compiler may optimize accordingly. -#if ABSL_OPTION_HARDENED == 1 && defined(NDEBUG) +#if (ABSL_OPTION_HARDENED == 1 || ABSL_OPTION_HARDENED == 2) && defined(NDEBUG) // Abort in hardened mode to avoid dangerous undefined behavior. #define ABSL_UNREACHABLE() \ do { \