aboutsummaryrefslogtreecommitdiff
path: root/absl/base/optimization.h
diff options
context:
space:
mode:
authorBenjamin Barenblat <bbaren@google.com>2022-07-12 21:47:19 -0400
committerBenjamin Barenblat <bbaren@google.com>2022-07-12 21:47:19 -0400
commitd055841ab4147dac20d5c46d04ca3a2fb13748b7 (patch)
tree15a01389c86f10a8844ff2a86bddf46640d065e8 /absl/base/optimization.h
parent2d23a3e16abfcf8f22ba850d67e972cc77e98874 (diff)
parent273292d1cfc0a94a65082ee350509af1d113344d (diff)
downloadabseil-d055841ab4147dac20d5c46d04ca3a2fb13748b7.tar.gz
abseil-d055841ab4147dac20d5c46d04ca3a2fb13748b7.tar.bz2
abseil-d055841ab4147dac20d5c46d04ca3a2fb13748b7.zip
Merge new upstream LTS 20220623.0
Diffstat (limited to 'absl/base/optimization.h')
-rw-r--r--absl/base/optimization.h30
1 files changed, 19 insertions, 11 deletions
diff --git a/absl/base/optimization.h b/absl/base/optimization.h
index d090be12..db5cc097 100644
--- a/absl/base/optimization.h
+++ b/absl/base/optimization.h
@@ -181,35 +181,43 @@
#define ABSL_PREDICT_TRUE(x) (x)
#endif
-// ABSL_INTERNAL_ASSUME(cond)
+// ABSL_ASSUME(cond)
+//
// Informs the compiler that a condition is always true and that it can assume
-// it to be true for optimization purposes. The call has undefined behavior if
-// the condition is false.
+// it to be true for optimization purposes.
+//
+// WARNING: If the condition is false, the program can produce undefined and
+// potentially dangerous behavior.
+//
// In !NDEBUG mode, the condition is checked with an assert().
-// NOTE: The expression must not have side effects, as it will only be evaluated
-// in some compilation modes and not others.
+//
+// NOTE: The expression must not have side effects, as it may only be evaluated
+// in some compilation modes and not others. Some compilers may issue a warning
+// if the compiler cannot prove the expression has no side effects. For example,
+// the expression should not use a function call since the compiler cannot prove
+// that a function call does not have side effects.
//
// Example:
//
// int x = ...;
-// ABSL_INTERNAL_ASSUME(x >= 0);
+// ABSL_ASSUME(x >= 0);
// // The compiler can optimize the division to a simple right shift using the
// // assumption specified above.
// int y = x / 16;
//
#if !defined(NDEBUG)
-#define ABSL_INTERNAL_ASSUME(cond) assert(cond)
+#define ABSL_ASSUME(cond) assert(cond)
#elif ABSL_HAVE_BUILTIN(__builtin_assume)
-#define ABSL_INTERNAL_ASSUME(cond) __builtin_assume(cond)
+#define ABSL_ASSUME(cond) __builtin_assume(cond)
#elif defined(__GNUC__) || ABSL_HAVE_BUILTIN(__builtin_unreachable)
-#define ABSL_INTERNAL_ASSUME(cond) \
+#define ABSL_ASSUME(cond) \
do { \
if (!(cond)) __builtin_unreachable(); \
} while (0)
#elif defined(_MSC_VER)
-#define ABSL_INTERNAL_ASSUME(cond) __assume(cond)
+#define ABSL_ASSUME(cond) __assume(cond)
#else
-#define ABSL_INTERNAL_ASSUME(cond) \
+#define ABSL_ASSUME(cond) \
do { \
static_cast<void>(false && (cond)); \
} while (0)