summaryrefslogtreecommitdiff
path: root/absl/base
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2020-07-28 11:13:39 -0700
committerGravatar Mark Barolak <mbar@google.com>2020-07-28 14:37:27 -0400
commitdea76486cb76c7e1032a5efc15b43538b7c5ce50 (patch)
tree4c7b7f6bbd39d399b446fdfd9cb6cb37c44e914a /absl/base
parentd39fe6cd6f5eb72dc741f17d3a143a6a5a56538a (diff)
Export of internal Abseil changes
-- e1d2e93a3328d9e4362c5510e81bd15ddd0dcf00 by Derek Mauro <dmauro@google.com>: ROLLBACK: Use auto-detected sanitizer attributes for ASAN, MSAN, and TSAN builds PiperOrigin-RevId: 323612219 -- 6fe0914715bcb680ac1dc533aae3461e2ca1ad50 by Derek Mauro <dmauro@google.com>: Use auto-detected sanitizer attributes for ASAN, MSAN, and TSAN builds PiperOrigin-RevId: 323597765 -- 9ad74e277348585f06a511aac31fff917a89a5d7 by Mark Barolak <mbar@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 323594550 -- 9e77ccb5adf7e9867cfa254105930f8fed19699d by Evan Brown <ezb@google.com>: Remove an unnecessary nullptr check in Cord::PrependTree(). We already check for nullptr at all callsites. PiperOrigin-RevId: 323583641 -- 31ab2355c1b91e474b67ff88b8597ad99f346511 by Gennadiy Rozental <rogeeff@google.com>: Avoid memory allocations while registering retired flags. PiperOrigin-RevId: 323523011 -- 33435e9b97b31763a80d3e41b5ab2459e862e99a by Jorg Brown <jorg@google.com>: 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
Diffstat (limited to 'absl/base')
-rw-r--r--absl/base/optimization.h2
-rw-r--r--absl/base/optimization_test.cc15
2 files changed, 7 insertions, 10 deletions
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<bool> 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