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
pull/754/head
Abseil Team 4 years ago committed by Mark Barolak
parent d39fe6cd6f
commit dea76486cb
  1. 2
      absl/base/optimization.h
  2. 15
      absl/base/optimization_test.cc
  3. 11
      absl/flags/flag.h
  4. 2
      absl/flags/flag_test_defs.cc
  5. 17
      absl/flags/internal/registry.h
  6. 17
      absl/flags/reflection.cc
  7. 2
      absl/strings/cord.cc
  8. 12
      absl/time/internal/cctz/src/time_zone_info.cc
  9. 2
      absl/time/internal/cctz/src/time_zone_info.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)

@ -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

@ -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_

@ -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");

@ -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

@ -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;
}
// --------------------------------------------------------------------

@ -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);

@ -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);

@ -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();

Loading…
Cancel
Save