aboutsummaryrefslogtreecommitdiff
path: root/absl
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
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')
-rw-r--r--absl/base/optimization.h2
-rw-r--r--absl/base/optimization_test.cc15
-rw-r--r--absl/flags/flag.h11
-rw-r--r--absl/flags/flag_test_defs.cc2
-rw-r--r--absl/flags/internal/registry.h17
-rw-r--r--absl/flags/reflection.cc17
-rw-r--r--absl/strings/cord.cc2
-rw-r--r--absl/time/internal/cctz/src/time_zone_info.cc12
-rw-r--r--absl/time/internal/cctz/src/time_zone_info.h2
9 files changed, 37 insertions, 43 deletions
diff --git a/absl/base/optimization.h b/absl/base/optimization.h
index 92bf9cd..2e31376 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 894b68f..e83369f 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
diff --git a/absl/flags/flag.h b/absl/flags/flag.h
index 90dc289..e170725 100644
--- a/absl/flags/flag.h
+++ b/absl/flags/flag.h
@@ -379,11 +379,10 @@ ABSL_NAMESPACE_END
//
// `default_value` is only used as a double check on the type. `explanation` is
// unused.
-// TODO(rogeeff): Return an anonymous struct instead of bool, and place it into
-// the unnamed namespace.
-#define ABSL_RETIRED_FLAG(type, flagname, default_value, explanation) \
- ABSL_ATTRIBUTE_UNUSED static const bool ignored_##flagname = \
- ([] { return type(default_value); }, \
- absl::flags_internal::RetiredFlag<type>(#flagname))
+// TODO(rogeeff): replace RETIRED_FLAGS with FLAGS once forward declarations of
+// retired flags are cleaned up.
+#define ABSL_RETIRED_FLAG(type, name, default_value, explanation) \
+ ABSL_ATTRIBUTE_UNUSED static const absl::flags_internal::RetiredFlag<type> \
+ RETIRED_FLAGS_##name(#name)
#endif // ABSL_FLAGS_FLAG_H_
diff --git a/absl/flags/flag_test_defs.cc b/absl/flags/flag_test_defs.cc
index 49f91de..3366c58 100644
--- a/absl/flags/flag_test_defs.cc
+++ b/absl/flags/flag_test_defs.cc
@@ -20,5 +20,3 @@
ABSL_FLAG(int, mistyped_int_flag, 0, "");
ABSL_FLAG(std::string, mistyped_string_flag, "", "");
-ABSL_RETIRED_FLAG(bool, old_bool_flag, true,
- "repetition of retired flag definition");
diff --git a/absl/flags/internal/registry.h b/absl/flags/internal/registry.h
index 6f5006a..5f85ded 100644
--- a/absl/flags/internal/registry.h
+++ b/absl/flags/internal/registry.h
@@ -74,13 +74,22 @@ bool RegisterCommandLineFlag(CommandLineFlag&);
//
// Retire flag with name "name" and type indicated by ops.
-bool Retire(const char* name, FlagFastTypeId type_id);
+void Retire(const char* name, FlagFastTypeId type_id, char* buf);
+
+constexpr size_t kRetiredFlagObjSize = 3 * sizeof(void*);
+constexpr size_t kRetiredFlagObjAlignment = alignof(void*);
// Registered a retired flag with name 'flag_name' and type 'T'.
template <typename T>
-inline bool RetiredFlag(const char* flag_name) {
- return flags_internal::Retire(flag_name, base_internal::FastTypeId<T>());
-}
+class RetiredFlag {
+ public:
+ explicit RetiredFlag(const char* flag_name) {
+ flags_internal::Retire(flag_name, base_internal::FastTypeId<T>(), buf_);
+ }
+
+ private:
+ alignas(kRetiredFlagObjAlignment) char buf_[kRetiredFlagObjSize];
+};
} // namespace flags_internal
ABSL_NAMESPACE_END
diff --git a/absl/flags/reflection.cc b/absl/flags/reflection.cc
index 1b02583..e4145b3 100644
--- a/absl/flags/reflection.cc
+++ b/absl/flags/reflection.cc
@@ -99,8 +99,6 @@ class FlagRegistryLock {
FlagRegistry& fr_;
};
-void DestroyRetiredFlag(CommandLineFlag& flag);
-
} // namespace
void FlagRegistry::RegisterFlag(CommandLineFlag& flag) {
@@ -125,8 +123,6 @@ void FlagRegistry::RegisterFlag(CommandLineFlag& flag) {
old_flag.Filename(), "' and '", flag.Filename(), "'."),
true);
} else if (old_flag.IsRetired()) {
- // Retired flag can just be deleted.
- DestroyRetiredFlag(flag);
return;
} else if (old_flag.Filename() != flag.Filename()) {
flags_internal::ReportUsageError(
@@ -241,17 +237,14 @@ class RetiredFlagObj final : public CommandLineFlag {
const FlagFastTypeId type_id_;
};
-void DestroyRetiredFlag(CommandLineFlag& flag) {
- assert(flag.IsRetired());
- delete static_cast<RetiredFlagObj*>(&flag);
-}
-
} // namespace
-bool Retire(const char* name, FlagFastTypeId type_id) {
- auto* flag = new flags_internal::RetiredFlagObj(name, type_id);
+void Retire(const char* name, FlagFastTypeId type_id, char* buf) {
+ static_assert(sizeof(RetiredFlagObj) == kRetiredFlagObjSize, "");
+ static_assert(alignof(RetiredFlagObj) == kRetiredFlagObjAlignment, "");
+ auto* flag = ::new (static_cast<void*>(buf))
+ flags_internal::RetiredFlagObj(name, type_id);
FlagRegistry::GlobalRegistry().RegisterFlag(*flag);
- return true;
}
// --------------------------------------------------------------------
diff --git a/absl/strings/cord.cc b/absl/strings/cord.cc
index 70c399c..920dcc6 100644
--- a/absl/strings/cord.cc
+++ b/absl/strings/cord.cc
@@ -549,7 +549,7 @@ void Cord::InlineRep::AppendTree(CordRep* tree) {
}
void Cord::InlineRep::PrependTree(CordRep* tree) {
- if (tree == nullptr) return;
+ assert(tree != nullptr);
size_t len = data_[kMaxInline];
if (len == 0) {
set_tree(tree);
diff --git a/absl/time/internal/cctz/src/time_zone_info.cc b/absl/time/internal/cctz/src/time_zone_info.cc
index c7bf044..8039353 100644
--- a/absl/time/internal/cctz/src/time_zone_info.cc
+++ b/absl/time/internal/cctz/src/time_zone_info.cc
@@ -295,7 +295,7 @@ bool TimeZoneInfo::EquivTransitions(std::uint_fast8_t tt1_index,
// Find/make a transition type with these attributes.
bool TimeZoneInfo::GetTransitionType(std::int_fast32_t utc_offset, bool is_dst,
const std::string& abbr,
- std::uint_fast8_t* index) {
+ std::uint_least8_t* index) {
std::size_t type_index = 0;
std::size_t abbr_index = abbreviations_.size();
for (; type_index != transition_types_.size(); ++type_index) {
@@ -334,7 +334,7 @@ bool TimeZoneInfo::ExtendTransitions() {
if (!ParsePosixSpec(future_spec_, &posix)) return false;
// Find transition type for the future std specification.
- std::uint_fast8_t std_ti;
+ std::uint_least8_t std_ti;
if (!GetTransitionType(posix.std_offset, false, posix.std_abbr, &std_ti))
return false;
@@ -345,7 +345,7 @@ bool TimeZoneInfo::ExtendTransitions() {
}
// Find transition type for the future dst specification.
- std::uint_fast8_t dst_ti;
+ std::uint_least8_t dst_ti;
if (!GetTransitionType(posix.dst_offset, true, posix.dst_abbr, &dst_ti))
return false;
@@ -365,10 +365,8 @@ bool TimeZoneInfo::ExtendTransitions() {
std::int_fast64_t jan1_time = jan1 - civil_second();
int jan1_weekday = ToPosixWeekday(get_weekday(jan1));
- Transition dst = {0, static_cast<uint_least8_t>(dst_ti), civil_second(),
- civil_second()};
- Transition std = {0, static_cast<uint_least8_t>(std_ti), civil_second(),
- civil_second()};
+ Transition dst = {0, dst_ti, civil_second(), civil_second()};
+ Transition std = {0, std_ti, civil_second(), civil_second()};
for (const year_t limit = last_year_ + 400;; ++last_year_) {
auto dst_trans_off = TransOffset(leap_year, jan1_weekday, posix.dst_start);
auto std_trans_off = TransOffset(leap_year, jan1_weekday, posix.dst_end);
diff --git a/absl/time/internal/cctz/src/time_zone_info.h b/absl/time/internal/cctz/src/time_zone_info.h
index 068e34b..2467ff5 100644
--- a/absl/time/internal/cctz/src/time_zone_info.h
+++ b/absl/time/internal/cctz/src/time_zone_info.h
@@ -96,7 +96,7 @@ class TimeZoneInfo : public TimeZoneIf {
};
bool GetTransitionType(std::int_fast32_t utc_offset, bool is_dst,
- const std::string& abbr, std::uint_fast8_t* index);
+ const std::string& abbr, std::uint_least8_t* index);
bool EquivTransitions(std::uint_fast8_t tt1_index,
std::uint_fast8_t tt2_index) const;
bool ExtendTransitions();