From dea76486cb76c7e1032a5efc15b43538b7c5ce50 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 28 Jul 2020 11:13:39 -0700 Subject: Export of internal Abseil changes -- e1d2e93a3328d9e4362c5510e81bd15ddd0dcf00 by Derek Mauro : ROLLBACK: Use auto-detected sanitizer attributes for ASAN, MSAN, and TSAN builds PiperOrigin-RevId: 323612219 -- 6fe0914715bcb680ac1dc533aae3461e2ca1ad50 by Derek Mauro : Use auto-detected sanitizer attributes for ASAN, MSAN, and TSAN builds PiperOrigin-RevId: 323597765 -- 9ad74e277348585f06a511aac31fff917a89a5d7 by Mark Barolak : Import of CCTZ from GitHub. PiperOrigin-RevId: 323594550 -- 9e77ccb5adf7e9867cfa254105930f8fed19699d by Evan Brown : Remove an unnecessary nullptr check in Cord::PrependTree(). We already check for nullptr at all callsites. PiperOrigin-RevId: 323583641 -- 31ab2355c1b91e474b67ff88b8597ad99f346511 by Gennadiy Rozental : Avoid memory allocations while registering retired flags. PiperOrigin-RevId: 323523011 -- 33435e9b97b31763a80d3e41b5ab2459e862e99a by Jorg Brown : Allow ABSL_PREDICT_FALSE to be used with a type that's explicitly convertible to bool. So far ABSL_PREDICT_TRUE could be used with these, but not ABSL_PREDICT_FALSE. PiperOrigin-RevId: 323514860 GitOrigin-RevId: e1d2e93a3328d9e4362c5510e81bd15ddd0dcf00 Change-Id: Iee5b030d9aec1ae2c0fe8997763cee7bd84b4090 --- absl/base/optimization.h | 2 +- absl/base/optimization_test.cc | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'absl/base') diff --git a/absl/base/optimization.h b/absl/base/optimization.h index 92bf9cd3..2e31376c 100644 --- a/absl/base/optimization.h +++ b/absl/base/optimization.h @@ -171,7 +171,7 @@ // to yield performance improvements. #if ABSL_HAVE_BUILTIN(__builtin_expect) || \ (defined(__GNUC__) && !defined(__clang__)) -#define ABSL_PREDICT_FALSE(x) (__builtin_expect(x, 0)) +#define ABSL_PREDICT_FALSE(x) (__builtin_expect(false || (x), false)) #define ABSL_PREDICT_TRUE(x) (__builtin_expect(false || (x), true)) #else #define ABSL_PREDICT_FALSE(x) (x) diff --git a/absl/base/optimization_test.cc b/absl/base/optimization_test.cc index 894b68f8..e83369f3 100644 --- a/absl/base/optimization_test.cc +++ b/absl/base/optimization_test.cc @@ -74,9 +74,8 @@ TEST(PredictTest, Pointer) { const int *null_intptr = nullptr; EXPECT_TRUE(ABSL_PREDICT_TRUE(good_intptr)); EXPECT_FALSE(ABSL_PREDICT_TRUE(null_intptr)); - // The following doesn't compile: - // EXPECT_TRUE(ABSL_PREDICT_FALSE(good_intptr)); - // EXPECT_FALSE(ABSL_PREDICT_FALSE(null_intptr)); + EXPECT_TRUE(ABSL_PREDICT_FALSE(good_intptr)); + EXPECT_FALSE(ABSL_PREDICT_FALSE(null_intptr)); } TEST(PredictTest, Optional) { @@ -85,9 +84,8 @@ TEST(PredictTest, Optional) { absl::optional no_value; EXPECT_TRUE(ABSL_PREDICT_TRUE(has_value)); EXPECT_FALSE(ABSL_PREDICT_TRUE(no_value)); - // The following doesn't compile: - // EXPECT_TRUE(ABSL_PREDICT_FALSE(has_value)); - // EXPECT_FALSE(ABSL_PREDICT_FALSE(no_value)); + EXPECT_TRUE(ABSL_PREDICT_FALSE(has_value)); + EXPECT_FALSE(ABSL_PREDICT_FALSE(no_value)); } class ImplictlyConvertibleToBool { @@ -124,9 +122,8 @@ TEST(PredictTest, ExplicitBoolConversion) { const ExplictlyConvertibleToBool is_false(false); if (!ABSL_PREDICT_TRUE(is_true)) ADD_FAILURE(); if (ABSL_PREDICT_TRUE(is_false)) ADD_FAILURE(); - // The following doesn't compile: - // if (!ABSL_PREDICT_FALSE(is_true)) ADD_FAILURE(); - // if (ABSL_PREDICT_FALSE(is_false)) ADD_FAILURE(); + if (!ABSL_PREDICT_FALSE(is_true)) ADD_FAILURE(); + if (ABSL_PREDICT_FALSE(is_false)) ADD_FAILURE(); } } // namespace -- cgit v1.2.3