Roll abseil_revision 9336be04a2..1065514ef3
Change Log:
https://chromium.googlesource.com/external/github.com/abseil/abseil-cpp/+log/9336be04a2..1065514ef3
Full diff:
https://chromium.googlesource.com/external/github.com/abseil/abseil-cpp/+/9336be04a2..1065514ef3
Bug: None
Change-Id: Ib32981a1f8775319d102530494d800fa5b65e9c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3341051
Reviewed-by: Danil Chapovalov <danilchap@chromium.org>
Commit-Queue: Mirko Bonadei <mbonadei@chromium.org>
Cr-Commit-Position: refs/heads/main@{#951902}
NOKEYCHECK=True
GitOrigin-RevId: a1f2c6eb56b07c38f48ca4565bc229d07d3d329f
diff --git a/CMake/AbseilHelpers.cmake b/CMake/AbseilHelpers.cmake
index 17c4f44..9ad2627 100644
--- a/CMake/AbseilHelpers.cmake
+++ b/CMake/AbseilHelpers.cmake
@@ -40,7 +40,8 @@
# LINKOPTS: List of link options
# PUBLIC: Add this so that this library will be exported under absl::
# Also in IDE, target will appear in Abseil folder while non PUBLIC will be in Abseil/internal.
-# TESTONLY: When added, this target will only be built if BUILD_TESTING=ON.
+# TESTONLY: When added, this target will only be built if both
+# BUILD_TESTING=ON and ABSL_BUILD_TESTING=ON.
#
# Note:
# By default, absl_cc_library will always create a library named absl_${NAME},
@@ -82,7 +83,7 @@
${ARGN}
)
- if(ABSL_CC_LIB_TESTONLY AND NOT BUILD_TESTING)
+ if(ABSL_CC_LIB_TESTONLY AND NOT (BUILD_TESTING AND ABSL_BUILD_TESTING))
return()
endif()
@@ -364,7 +365,7 @@
# GTest::gtest_main
# )
function(absl_cc_test)
- if(NOT BUILD_TESTING)
+ if(NOT (BUILD_TESTING AND ABSL_BUILD_TESTING))
return()
endif()
diff --git a/CMake/README.md b/CMake/README.md
index f8b27e6..8134615 100644
--- a/CMake/README.md
+++ b/CMake/README.md
@@ -20,8 +20,10 @@
### Step-by-Step Instructions
1. If you want to build the Abseil tests, integrate the Abseil dependency
-[Google Test](https://github.com/google/googletest) into your CMake project. To disable Abseil tests, you have to pass
-`-DBUILD_TESTING=OFF` when configuring your project with CMake.
+[Google Test](https://github.com/google/googletest) into your CMake
+project. To disable Abseil tests, you have to pass either
+`-DBUILD_TESTING=OFF` or `-DABSL_BUILD_TESTING=OFF` when configuring your
+project with CMake.
2. Download Abseil and copy it into a subdirectory in your CMake project or add
Abseil as a [git submodule](https://git-scm.com/docs/git-submodule) in your
@@ -91,7 +93,8 @@
### Running Abseil Tests with CMake
-Use the `-DBUILD_TESTING=ON` flag to run Abseil tests.
+Use the `-DABSL_BUILD_TESTING=ON` flag to run Abseil tests. Note that
+BUILD_TESTING must also be on (the default).
You will need to provide Abseil with a Googletest dependency. There are two
options for how to do this:
@@ -109,7 +112,7 @@
cd path/to/abseil-cpp
mkdir build
cd build
-cmake -DBUILD_TESTING=ON -DABSL_USE_GOOGLETEST_HEAD=ON ..
+cmake -DABSL_BUILD_TESTING=ON -DABSL_USE_GOOGLETEST_HEAD=ON ..
make -j
ctest
```
@@ -175,7 +178,7 @@
## Google Test Options
-`-DBUILD_TESTING=ON` must be set to enable testing
+`-DABSL_BUILD_TESTING=ON` must be set to enable testing
- Have Abseil download and build Google Test for you: `-DABSL_USE_EXTERNAL_GOOGLETEST=OFF` (default)
- Download and build latest Google Test: `-DABSL_USE_GOOGLETEST_HEAD=ON`
diff --git a/CMake/install_test_project/test.sh b/CMake/install_test_project/test.sh
index aecbb8f..cc028ba 100755
--- a/CMake/install_test_project/test.sh
+++ b/CMake/install_test_project/test.sh
@@ -55,7 +55,7 @@
-DABSL_USE_EXTERNAL_GOOGLETEST=ON \
-DABSL_FIND_GOOGLETEST=ON \
-DCMAKE_BUILD_TYPE=Release \
- -DBUILD_TESTING=ON \
+ -DABSL_BUILD_TESTING=ON \
-DBUILD_SHARED_LIBS="${build_shared_libs}"
make -j $(nproc)
ctest -j $(nproc) --output-on-failure
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a1400b7..ff49ac1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,10 +46,6 @@
cmake_policy(SET CMP0091 NEW)
endif (POLICY CMP0091)
-# Set BUILD_TESTING to OFF by default.
-# This must come before the project() and include(CTest) lines.
-OPTION(BUILD_TESTING "Build tests" OFF)
-
project(absl LANGUAGES CXX)
include(CTest)
@@ -111,6 +107,9 @@
include(CMakeDependentOption)
+option(ABSL_BUILD_TESTING
+ "If ON, Abseil will build all of Abseil's own tests." OFF)
+
option(ABSL_USE_EXTERNAL_GOOGLETEST
"If ON, Abseil will assume that the targets for GoogleTest are already provided by the including project. This makes sense when Abseil is used with add_subproject." OFF)
@@ -130,7 +129,7 @@
"If ABSL_USE_GOOGLETEST_HEAD is OFF and ABSL_GOOGLETEST_URL is not set, specifies the directory of a local GoogleTest checkout."
)
-if(BUILD_TESTING)
+if(BUILD_TESTING AND ABSL_BUILD_TESTING)
## check targets
if (ABSL_USE_EXTERNAL_GOOGLETEST)
if (ABSL_FIND_GOOGLETEST)
diff --git a/README.chromium b/README.chromium
index 60774f6..f8a5720 100644
--- a/README.chromium
+++ b/README.chromium
@@ -4,7 +4,7 @@
License: Apache 2.0
License File: LICENSE
Version: 0
-Revision: 9336be04a242237cd41a525bedfcf3be1bb55377
+Revision: 1065514ef332d036f3437e950e78d35ce6b7c740
Security Critical: yes
Description:
diff --git a/absl/base/config.h b/absl/base/config.h
index c29b206..373aa0c 100644
--- a/absl/base/config.h
+++ b/absl/base/config.h
@@ -751,8 +751,6 @@
// a compiler instrumentation module and a run-time library.
#ifdef ABSL_HAVE_MEMORY_SANITIZER
#error "ABSL_HAVE_MEMORY_SANITIZER cannot be directly set."
-#elif defined(__SANITIZE_MEMORY__)
-#define ABSL_HAVE_MEMORY_SANITIZER 1
#elif !defined(__native_client__) && ABSL_HAVE_FEATURE(memory_sanitizer)
#define ABSL_HAVE_MEMORY_SANITIZER 1
#endif
@@ -779,6 +777,28 @@
#define ABSL_HAVE_ADDRESS_SANITIZER 1
#endif
+// ABSL_HAVE_HWADDRESS_SANITIZER
+//
+// Hardware-Assisted AddressSanitizer (or HWASAN) is even faster than asan
+// memory error detector which can use CPU features like ARM TBI, Intel LAM or
+// AMD UAI.
+#ifdef ABSL_HAVE_HWADDRESS_SANITIZER
+#error "ABSL_HAVE_HWADDRESS_SANITIZER cannot be directly set."
+#elif defined(__SANITIZE_HWADDRESS__)
+#define ABSL_HAVE_HWADDRESS_SANITIZER 1
+#elif ABSL_HAVE_FEATURE(hwaddress_sanitizer)
+#define ABSL_HAVE_HWADDRESS_SANITIZER 1
+#endif
+
+// ABSL_HAVE_LEAK_SANITIZER
+//
+// LeakSanitizer (or lsan) is a detector of memory leaks.
+#ifdef ABSL_HAVE_LEAK_SANITIZER
+#error "ABSL_HAVE_LEAK_SANITIZER cannot be directly set."
+#elif ABSL_HAVE_FEATURE(leak_sanitizer)
+#define ABSL_HAVE_LEAK_SANITIZER 1
+#endif
+
// ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
//
// Class template argument deduction is a language feature added in C++17.
diff --git a/absl/base/internal/direct_mmap.h b/absl/base/internal/direct_mmap.h
index 274054c..7037094 100644
--- a/absl/base/internal/direct_mmap.h
+++ b/absl/base/internal/direct_mmap.h
@@ -80,7 +80,7 @@
(defined(__PPC__) && !defined(__PPC64__)) || \
(defined(__riscv) && __riscv_xlen == 32) || \
(defined(__s390__) && !defined(__s390x__)) || \
- (defined(__sparc__) && !defined(__arch64__))
+ (defined(__sparc__) && !defined(__aarch64__))
// On these architectures, implement mmap with mmap2.
static int pagesize = 0;
if (pagesize == 0) {
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h
index d4b72ab..ad12f41 100644
--- a/absl/container/internal/raw_hash_set.h
+++ b/absl/container/internal/raw_hash_set.h
@@ -201,7 +201,7 @@
template <typename T>
uint32_t TrailingZeros(T x) {
ABSL_INTERNAL_ASSUME(x != 0);
- return countr_zero(x);
+ return static_cast<uint32_t>(countr_zero(x));
}
// An abstraction over a bitmask. It provides an easy way to iterate through the
@@ -230,7 +230,7 @@
return *this;
}
explicit operator bool() const { return mask_ != 0; }
- int operator*() const { return LowestBitSet(); }
+ uint32_t operator*() const { return LowestBitSet(); }
uint32_t LowestBitSet() const {
return container_internal::TrailingZeros(mask_) >> Shift;
}
@@ -248,7 +248,7 @@
uint32_t LeadingZeros() const {
constexpr int total_significant_bits = SignificantBits << Shift;
constexpr int extra_bits = sizeof(T) * 8 - total_significant_bits;
- return countl_zero(mask_ << extra_bits) >> Shift;
+ return static_cast<uint32_t>(countl_zero(mask_ << extra_bits)) >> Shift;
}
private:
@@ -360,7 +360,7 @@
BitMask<uint32_t, kWidth> Match(h2_t hash) const {
auto match = _mm_set1_epi8(hash);
return BitMask<uint32_t, kWidth>(
- _mm_movemask_epi8(_mm_cmpeq_epi8(match, ctrl)));
+ static_cast<uint32_t>(_mm_movemask_epi8(_mm_cmpeq_epi8(match, ctrl))));
}
// Returns a bitmask representing the positions of empty slots.
@@ -368,7 +368,7 @@
#if ABSL_INTERNAL_RAW_HASH_SET_HAVE_SSSE3
// This only works because ctrl_t::kEmpty is -128.
return BitMask<uint32_t, kWidth>(
- _mm_movemask_epi8(_mm_sign_epi8(ctrl, ctrl)));
+ static_cast<uint32_t>(_mm_movemask_epi8(_mm_sign_epi8(ctrl, ctrl))));
#else
return Match(static_cast<h2_t>(ctrl_t::kEmpty));
#endif
@@ -376,14 +376,15 @@
// Returns a bitmask representing the positions of empty or deleted slots.
BitMask<uint32_t, kWidth> MatchEmptyOrDeleted() const {
- auto special = _mm_set1_epi8(static_cast<int8_t>(ctrl_t::kSentinel));
+ auto special = _mm_set1_epi8(static_cast<uint8_t>(ctrl_t::kSentinel));
return BitMask<uint32_t, kWidth>(
- _mm_movemask_epi8(_mm_cmpgt_epi8_fixed(special, ctrl)));
+ static_cast<uint32_t>(
+ _mm_movemask_epi8(_mm_cmpgt_epi8_fixed(special, ctrl))));
}
// Returns the number of trailing empty or deleted elements in the group.
uint32_t CountLeadingEmptyOrDeleted() const {
- auto special = _mm_set1_epi8(static_cast<int8_t>(ctrl_t::kSentinel));
+ auto special = _mm_set1_epi8(static_cast<uint8_t>(ctrl_t::kSentinel));
return TrailingZeros(static_cast<uint32_t>(
_mm_movemask_epi8(_mm_cmpgt_epi8_fixed(special, ctrl)) + 1));
}
@@ -1465,7 +1466,7 @@
auto seq = probe(ctrl_, hash, capacity_);
while (true) {
Group g{ctrl_ + seq.offset()};
- for (int i : g.Match(H2(hash))) {
+ for (uint32_t i : g.Match(H2(hash))) {
if (ABSL_PREDICT_TRUE(PolicyTraits::apply(
EqualElement<K>{key, eq_ref()},
PolicyTraits::element(slots_ + seq.offset(i)))))
@@ -1610,7 +1611,7 @@
void erase_meta_only(const_iterator it) {
assert(IsFull(*it.inner_.ctrl_) && "erasing a dangling iterator");
--size_;
- const size_t index = it.inner_.ctrl_ - ctrl_;
+ const size_t index = static_cast<size_t>(it.inner_.ctrl_ - ctrl_);
const size_t index_before = (index - Group::kWidth) & capacity_;
const auto empty_after = Group(it.inner_.ctrl_).MatchEmpty();
const auto empty_before = Group(ctrl_ + index_before).MatchEmpty();
@@ -1832,7 +1833,7 @@
auto seq = probe(ctrl_, hash, capacity_);
while (true) {
Group g{ctrl_ + seq.offset()};
- for (int i : g.Match(H2(hash))) {
+ for (uint32_t i : g.Match(H2(hash))) {
if (ABSL_PREDICT_TRUE(PolicyTraits::element(slots_ + seq.offset(i)) ==
elem))
return true;
@@ -1864,7 +1865,7 @@
auto seq = probe(ctrl_, hash, capacity_);
while (true) {
Group g{ctrl_ + seq.offset()};
- for (int i : g.Match(H2(hash))) {
+ for (uint32_t i : g.Match(H2(hash))) {
if (ABSL_PREDICT_TRUE(PolicyTraits::apply(
EqualElement<K>{key, eq_ref()},
PolicyTraits::element(slots_ + seq.offset(i)))))
@@ -1984,7 +1985,7 @@
auto seq = probe(set.ctrl_, hash, set.capacity_);
while (true) {
container_internal::Group g{set.ctrl_ + seq.offset()};
- for (int i : g.Match(container_internal::H2(hash))) {
+ for (uint32_t i : g.Match(container_internal::H2(hash))) {
if (Traits::apply(
typename Set::template EqualElement<typename Set::key_type>{
key, set.eq_ref()},
diff --git a/absl/container/internal/raw_hash_set_benchmark.cc b/absl/container/internal/raw_hash_set_benchmark.cc
index c886d3a..146ef43 100644
--- a/absl/container/internal/raw_hash_set_benchmark.cc
+++ b/absl/container/internal/raw_hash_set_benchmark.cc
@@ -330,6 +330,7 @@
h2_t h = 1;
for (auto _ : state) {
::benchmark::DoNotOptimize(h);
+ ::benchmark::DoNotOptimize(g);
::benchmark::DoNotOptimize(g.Match(h));
}
}
@@ -339,7 +340,10 @@
std::array<ctrl_t, Group::kWidth> group;
Iota(group.begin(), group.end(), -4);
Group g{group.data()};
- for (auto _ : state) ::benchmark::DoNotOptimize(g.MatchEmpty());
+ for (auto _ : state) {
+ ::benchmark::DoNotOptimize(g);
+ ::benchmark::DoNotOptimize(g.MatchEmpty());
+ }
}
BENCHMARK(BM_Group_MatchEmpty);
@@ -347,7 +351,10 @@
std::array<ctrl_t, Group::kWidth> group;
Iota(group.begin(), group.end(), -4);
Group g{group.data()};
- for (auto _ : state) ::benchmark::DoNotOptimize(g.MatchEmptyOrDeleted());
+ for (auto _ : state) {
+ ::benchmark::DoNotOptimize(g);
+ ::benchmark::DoNotOptimize(g.MatchEmptyOrDeleted());
+ }
}
BENCHMARK(BM_Group_MatchEmptyOrDeleted);
@@ -355,8 +362,10 @@
std::array<ctrl_t, Group::kWidth> group;
Iota(group.begin(), group.end(), -2);
Group g{group.data()};
- for (auto _ : state)
+ for (auto _ : state) {
+ ::benchmark::DoNotOptimize(g);
::benchmark::DoNotOptimize(g.CountLeadingEmptyOrDeleted());
+ }
}
BENCHMARK(BM_Group_CountLeadingEmptyOrDeleted);
@@ -364,7 +373,10 @@
std::array<ctrl_t, Group::kWidth> group;
Iota(group.begin(), group.end(), -2);
Group g{group.data()};
- for (auto _ : state) ::benchmark::DoNotOptimize(*g.MatchEmptyOrDeleted());
+ for (auto _ : state) {
+ ::benchmark::DoNotOptimize(g);
+ ::benchmark::DoNotOptimize(*g.MatchEmptyOrDeleted());
+ }
}
BENCHMARK(BM_Group_MatchFirstEmptyOrDeleted);
diff --git a/absl/debugging/internal/address_is_readable.cc b/absl/debugging/internal/address_is_readable.cc
index 26df328..4be6256 100644
--- a/absl/debugging/internal/address_is_readable.cc
+++ b/absl/debugging/internal/address_is_readable.cc
@@ -30,16 +30,12 @@
ABSL_NAMESPACE_END
} // namespace absl
-#else
+#else // __linux__ && !__ANDROID__
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/syscall.h>
-#include <sys/types.h>
+#include <stdint.h>
+#include <syscall.h>
#include <unistd.h>
-#include <cerrno>
-
#include "absl/base/internal/errno_saver.h"
#include "absl/base/internal/raw_logging.h"
@@ -47,60 +43,54 @@
ABSL_NAMESPACE_BEGIN
namespace debugging_internal {
+// NOTE: be extra careful about adding any interposable function calls here
+// (such as open(), read(), etc.). These symbols may be interposed and will get
+// invoked in contexts they don't expect.
+//
+// NOTE: any new system calls here may also require sandbox reconfiguration.
+//
bool AddressIsReadable(const void *addr) {
- int fd = 0;
+ // Align address on 8-byte boundary. On aarch64, checking last
+ // byte before inaccessible page returned unexpected EFAULT.
+ const uintptr_t u_addr = reinterpret_cast<uintptr_t>(addr) & ~7;
+ addr = reinterpret_cast<const void *>(u_addr);
+
+ // rt_sigprocmask below will succeed for this input.
+ if (addr == nullptr) return false;
+
absl::base_internal::ErrnoSaver errno_saver;
- for (int j = 0; j < 2; j++) {
- // Here we probe with some syscall which
- // - accepts a one-byte region of user memory as input
- // - tests for EFAULT before other validation
- // - has no problematic side-effects
- //
- // connect(2) works for this. It copies the address into kernel
- // memory before any validation beyond requiring an open fd.
- // But a one byte address is never valid (sa_family is two bytes),
- // so the call cannot succeed and change any state.
- //
- // This strategy depends on Linux implementation details,
- // so we rely on the test to alert us if it stops working.
- //
- // Some discarded past approaches:
- // - msync() doesn't reject PROT_NONE regions
- // - write() on /dev/null doesn't return EFAULT
- // - write() on a pipe requires creating it and draining the writes
- //
- // Use syscall(SYS_connect, ...) instead of connect() to prevent ASAN
- // and other checkers from complaining about accesses to arbitrary memory.
- do {
- ABSL_RAW_CHECK(syscall(SYS_connect, fd, addr, 1) == -1,
- "should never succeed");
- } while (errno == EINTR);
- if (errno == EFAULT) return false;
- if (errno == EBADF) {
- if (j != 0) {
- // Unclear what happened.
- ABSL_RAW_LOG(ERROR, "unexpected EBADF on fd %d", fd);
- return false;
- }
- // fd 0 must have been closed. Try opening it again.
- // Note: we shouldn't leak too many file descriptors here, since we expect
- // to get fd==0 reopened.
- fd = open("/dev/null", O_RDONLY);
- if (fd == -1) {
- ABSL_RAW_LOG(ERROR, "can't open /dev/null");
- return false;
- }
- } else {
- // probably EINVAL or ENOTSOCK; we got past EFAULT validation.
- return true;
- }
- }
- ABSL_RAW_CHECK(false, "unreachable");
- return false;
+
+ // Here we probe with some syscall which
+ // - accepts an 8-byte region of user memory as input
+ // - tests for EFAULT before other validation
+ // - has no problematic side-effects
+ //
+ // rt_sigprocmask(2) works for this. It copies sizeof(kernel_sigset_t)==8
+ // bytes from the address into the kernel memory before any validation.
+ //
+ // The call can never succeed, since the `how` parameter is not one of
+ // SIG_BLOCK, SIG_UNBLOCK, SIG_SETMASK.
+ //
+ // This strategy depends on Linux implementation details,
+ // so we rely on the test to alert us if it stops working.
+ //
+ // Some discarded past approaches:
+ // - msync() doesn't reject PROT_NONE regions
+ // - write() on /dev/null doesn't return EFAULT
+ // - write() on a pipe requires creating it and draining the writes
+ // - connect() works but is problematic for sandboxes and needs a valid
+ // file descriptor
+ //
+ // This can never succeed (invalid first argument to sigprocmask).
+ ABSL_RAW_CHECK(syscall(SYS_rt_sigprocmask, ~0, addr, nullptr,
+ /*sizeof(kernel_sigset_t)*/ 8) == -1,
+ "unexpected success");
+ ABSL_RAW_CHECK(errno == EFAULT || errno == EINVAL, "unexpected errno");
+ return errno != EFAULT;
}
} // namespace debugging_internal
ABSL_NAMESPACE_END
} // namespace absl
-#endif
+#endif // __linux__ && !__ANDROID__
diff --git a/absl/flags/declare.h b/absl/flags/declare.h
index b9794d8..a791b66 100644
--- a/absl/flags/declare.h
+++ b/absl/flags/declare.h
@@ -60,6 +60,10 @@
// The ABSL_DECLARE_FLAG(type, name) macro expands to:
//
// extern absl::Flag<type> FLAGS_name;
-#define ABSL_DECLARE_FLAG(type, name) extern ::absl::Flag<type> FLAGS_##name
+#define ABSL_DECLARE_FLAG(type, name) \
+ extern absl::Flag<type> FLAGS_##name; \
+ namespace absl /* block flags in namespaces */ {} \
+ /* second redeclaration is to allow applying attributes */ \
+ extern absl::Flag<type> FLAGS_##name
#endif // ABSL_FLAGS_DECLARE_H_
diff --git a/absl/random/internal/randen_detect.cc b/absl/random/internal/randen_detect.cc
index bbe7b96..9bb58fc 100644
--- a/absl/random/internal/randen_detect.cc
+++ b/absl/random/internal/randen_detect.cc
@@ -40,7 +40,6 @@
#if defined(ABSL_INTERNAL_USE_X86_CPUID)
#if defined(_WIN32) || defined(_WIN64)
#include <intrin.h> // NOLINT(build/include_order)
-#pragma intrinsic(__cpuid)
#else
// MSVC-equivalent __cpuid intrinsic function.
static void __cpuid(int cpu_info[4], int info_type) {
diff --git a/absl/strings/ascii.h b/absl/strings/ascii.h
index b46bc71..9b8e5d1 100644
--- a/absl/strings/ascii.h
+++ b/absl/strings/ascii.h
@@ -133,7 +133,7 @@
// ascii_isprint()
//
-// Determines whether the given character is printable, including whitespace.
+// Determines whether the given character is printable, including spaces.
inline bool ascii_isprint(unsigned char c) { return c >= 32 && c < 127; }
// ascii_isgraph()
diff --git a/absl/strings/cord.cc b/absl/strings/cord.cc
index 5905bac..425b4be 100644
--- a/absl/strings/cord.cc
+++ b/absl/strings/cord.cc
@@ -311,11 +311,10 @@
constexpr unsigned char Cord::InlineRep::kMaxInline;
-inline void Cord::InlineRep::set_data(const char* data, size_t n,
- bool nullify_tail) {
+inline void Cord::InlineRep::set_data(const char* data, size_t n) {
static_assert(kMaxInline == 15, "set_data is hard-coded for a length of 15");
- cord_internal::SmallMemmove(data_.as_chars(), data, n, nullify_tail);
+ cord_internal::SmallMemmove<true>(data_.as_chars(), data, n);
set_inline_size(n);
}
@@ -375,7 +374,8 @@
}
void Cord::InlineRep::AppendTree(CordRep* tree, MethodIdentifier method) {
- if (tree == nullptr) return;
+ assert(tree != nullptr);
+ assert(tree->length != 0);
assert(!tree->IsCrc());
if (data_.is_tree()) {
AppendTreeToTree(tree, method);
@@ -412,6 +412,7 @@
void Cord::InlineRep::PrependTree(CordRep* tree, MethodIdentifier method) {
assert(tree != nullptr);
+ assert(tree->length != 0);
assert(!tree->IsCrc());
if (data_.is_tree()) {
PrependTreeToTree(tree, method);
@@ -549,7 +550,7 @@
: contents_(InlineData::kDefaultInit) {
const size_t n = src.size();
if (n <= InlineRep::kMaxInline) {
- contents_.set_data(src.data(), n, true);
+ contents_.set_data(src.data(), n);
} else {
CordRep* rep = NewTree(src.data(), n, 0);
contents_.EmplaceTree(rep, method);
@@ -559,7 +560,7 @@
template <typename T, Cord::EnableIfString<T>>
Cord::Cord(T&& src) : contents_(InlineData::kDefaultInit) {
if (src.size() <= InlineRep::kMaxInline) {
- contents_.set_data(src.data(), src.size(), true);
+ contents_.set_data(src.data(), src.size());
} else {
CordRep* rep = CordRepFromString(std::forward<T>(src));
contents_.EmplaceTree(rep, CordzUpdateTracker::kConstructorString);
@@ -610,7 +611,7 @@
// - MaybeUntrackCord must be called before set_data() clobbers cordz_info.
// - set_data() must be called before Unref(tree) as it may reference tree.
if (tree != nullptr) CordzInfo::MaybeUntrackCord(contents_.cordz_info());
- contents_.set_data(data, length, true);
+ contents_.set_data(data, length);
if (tree != nullptr) CordRep::Unref(tree);
return *this;
}
@@ -1014,9 +1015,7 @@
CordRep* tree = contents_.tree();
if (tree == nullptr) {
- // sub_cord is newly constructed, no need to re-zero-out the tail of
- // contents_ memory.
- sub_cord.contents_.set_data(contents_.data() + pos, new_size, false);
+ sub_cord.contents_.set_data(contents_.data() + pos, new_size);
return sub_cord;
}
diff --git a/absl/strings/cord.h b/absl/strings/cord.h
index 27d3475..3bbd763 100644
--- a/absl/strings/cord.h
+++ b/absl/strings/cord.h
@@ -763,9 +763,8 @@
bool empty() const;
size_t size() const;
const char* data() const; // Returns nullptr if holding pointer
- void set_data(const char* data, size_t n,
- bool nullify_tail); // Discards pointer, if any
- char* set_data(size_t n); // Write data to the result
+ void set_data(const char* data, size_t n); // Discards pointer, if any
+ char* set_data(size_t n); // Write data to the result
// Returns nullptr if holding bytes
absl::cord_internal::CordRep* tree() const;
absl::cord_internal::CordRep* as_tree() const;
@@ -857,7 +856,7 @@
bool is_profiled() const { return data_.is_tree() && data_.is_profiled(); }
// Returns the available inlined capacity, or 0 if is_tree() == true.
- size_t inline_capacity() const {
+ size_t remaining_inline_capacity() const {
return data_.is_tree() ? 0 : kMaxInline - data_.inline_size();
}
@@ -968,8 +967,8 @@
// Fast implementation of memmove for up to 15 bytes. This implementation is
// safe for overlapping regions. If nullify_tail is true, the destination is
// padded with '\0' up to 16 bytes.
-inline void SmallMemmove(char* dst, const char* src, size_t n,
- bool nullify_tail = false) {
+template <bool nullify_tail = false>
+inline void SmallMemmove(char* dst, const char* src, size_t n) {
if (n >= 8) {
assert(n <= 16);
uint64_t buf1;
@@ -1006,22 +1005,16 @@
}
// Does non-template-specific `CordRepExternal` initialization.
-// Expects `data` to be non-empty.
+// Requires `data` to be non-empty.
void InitializeCordRepExternal(absl::string_view data, CordRepExternal* rep);
// Creates a new `CordRep` that owns `data` and `releaser` and returns a pointer
-// to it, or `nullptr` if `data` was empty.
+// to it. Requires `data` to be non-empty.
template <typename Releaser>
// NOLINTNEXTLINE - suppress clang-tidy raw pointer return.
CordRep* NewExternalRep(absl::string_view data, Releaser&& releaser) {
+ assert(!data.empty());
using ReleaserType = absl::decay_t<Releaser>;
- if (data.empty()) {
- // Never create empty external nodes.
- InvokeReleaser(Rank0{}, ReleaserType(std::forward<Releaser>(releaser)),
- data);
- return nullptr;
- }
-
CordRepExternal* rep = new CordRepExternalImpl<ReleaserType>(
std::forward<Releaser>(releaser), 0);
InitializeCordRepExternal(data, rep);
@@ -1041,10 +1034,15 @@
template <typename Releaser>
Cord MakeCordFromExternal(absl::string_view data, Releaser&& releaser) {
Cord cord;
- if (auto* rep = ::absl::cord_internal::NewExternalRep(
- data, std::forward<Releaser>(releaser))) {
- cord.contents_.EmplaceTree(rep,
+ if (ABSL_PREDICT_TRUE(!data.empty())) {
+ cord.contents_.EmplaceTree(::absl::cord_internal::NewExternalRep(
+ data, std::forward<Releaser>(releaser)),
Cord::MethodIdentifier::kMakeCordFromExternal);
+ } else {
+ using ReleaserType = absl::decay_t<Releaser>;
+ cord_internal::InvokeReleaser(
+ cord_internal::Rank0{}, ReleaserType(std::forward<Releaser>(releaser)),
+ data);
}
return cord;
}
diff --git a/absl/strings/cord_test.cc b/absl/strings/cord_test.cc
index ea865cc..a22db0b 100644
--- a/absl/strings/cord_test.cc
+++ b/absl/strings/cord_test.cc
@@ -1370,31 +1370,64 @@
}
TEST_P(CordTest, ConstructFromExternalReferenceQualifierOverloads) {
- struct Releaser {
- void operator()(absl::string_view) & { *lvalue_invoked = true; }
- void operator()(absl::string_view) && { *rvalue_invoked = true; }
+ enum InvokedAs { kMissing, kLValue, kRValue };
+ enum CopiedAs { kNone, kMove, kCopy };
+ struct Tracker {
+ CopiedAs copied_as = kNone;
+ InvokedAs invoked_as = kMissing;
- bool* lvalue_invoked;
- bool* rvalue_invoked;
+ void Record(InvokedAs rhs) {
+ ASSERT_EQ(invoked_as, kMissing);
+ invoked_as = rhs;
+ }
+
+ void Record(CopiedAs rhs) {
+ if (copied_as == kNone || rhs == kCopy) copied_as = rhs;
+ }
+ } tracker;
+
+ class Releaser {
+ public:
+ explicit Releaser(Tracker* tracker) : tr_(tracker) { *tracker = Tracker(); }
+ Releaser(Releaser&& rhs) : tr_(rhs.tr_) { tr_->Record(kMove); }
+ Releaser(const Releaser& rhs) : tr_(rhs.tr_) { tr_->Record(kCopy); }
+
+ void operator()(absl::string_view) & { tr_->Record(kLValue); }
+ void operator()(absl::string_view) && { tr_->Record(kRValue); }
+
+ private:
+ Tracker* tr_;
};
- bool lvalue_invoked = false;
- bool rvalue_invoked = false;
- Releaser releaser = {&lvalue_invoked, &rvalue_invoked};
- (void)MaybeHardened(absl::MakeCordFromExternal("", releaser));
- EXPECT_FALSE(lvalue_invoked);
- EXPECT_TRUE(rvalue_invoked);
- rvalue_invoked = false;
+ const Releaser releaser1(&tracker);
+ (void)MaybeHardened(absl::MakeCordFromExternal("", releaser1));
+ EXPECT_EQ(tracker.copied_as, kCopy);
+ EXPECT_EQ(tracker.invoked_as, kRValue);
- (void)MaybeHardened(absl::MakeCordFromExternal("dummy", releaser));
- EXPECT_FALSE(lvalue_invoked);
- EXPECT_TRUE(rvalue_invoked);
- rvalue_invoked = false;
+ const Releaser releaser2(&tracker);
+ (void)MaybeHardened(absl::MakeCordFromExternal("", releaser2));
+ EXPECT_EQ(tracker.copied_as, kCopy);
+ EXPECT_EQ(tracker.invoked_as, kRValue);
- // NOLINTNEXTLINE: suppress clang-tidy std::move on trivially copyable type.
- (void)MaybeHardened(absl::MakeCordFromExternal("dummy", std::move(releaser)));
- EXPECT_FALSE(lvalue_invoked);
- EXPECT_TRUE(rvalue_invoked);
+ Releaser releaser3(&tracker);
+ (void)MaybeHardened(absl::MakeCordFromExternal("", std::move(releaser3)));
+ EXPECT_EQ(tracker.copied_as, kMove);
+ EXPECT_EQ(tracker.invoked_as, kRValue);
+
+ Releaser releaser4(&tracker);
+ (void)MaybeHardened(absl::MakeCordFromExternal("dummy", releaser4));
+ EXPECT_EQ(tracker.copied_as, kCopy);
+ EXPECT_EQ(tracker.invoked_as, kRValue);
+
+ const Releaser releaser5(&tracker);
+ (void)MaybeHardened(absl::MakeCordFromExternal("dummy", releaser5));
+ EXPECT_EQ(tracker.copied_as, kCopy);
+ EXPECT_EQ(tracker.invoked_as, kRValue);
+
+ Releaser releaser6(&tracker);
+ (void)MaybeHardened(absl::MakeCordFromExternal("foo", std::move(releaser6)));
+ EXPECT_EQ(tracker.copied_as, kMove);
+ EXPECT_EQ(tracker.invoked_as, kRValue);
}
TEST_P(CordTest, ExternalMemoryBasicUsage) {
diff --git a/absl/strings/substitute.h b/absl/strings/substitute.h
index 151c56f..dae4e63 100644
--- a/absl/strings/substitute.h
+++ b/absl/strings/substitute.h
@@ -159,8 +159,8 @@
Arg(Hex hex); // NOLINT(runtime/explicit)
Arg(Dec dec); // NOLINT(runtime/explicit)
- // vector<bool>::reference and const_reference require special help to
- // convert to `AlphaNum` because it requires two user defined conversions.
+ // vector<bool>::reference and const_reference require special help to convert
+ // to `Arg` because it requires two user defined conversions.
template <typename T,
absl::enable_if_t<
std::is_class<T>::value &&
diff --git a/absl/synchronization/mutex.cc b/absl/synchronization/mutex.cc
index 76ad41f..3af4cda 100644
--- a/absl/synchronization/mutex.cc
+++ b/absl/synchronization/mutex.cc
@@ -2327,7 +2327,7 @@
base_internal::CycleClock::Now() - enqueue_timestamp;
mutex_tracer("slow release", this, wait_cycles);
ABSL_TSAN_MUTEX_PRE_DIVERT(this, 0);
- submit_profile_data(enqueue_timestamp);
+ submit_profile_data(wait_cycles);
ABSL_TSAN_MUTEX_POST_DIVERT(this, 0);
}
}
diff --git a/absl/synchronization/notification.h b/absl/synchronization/notification.h
index 9a354ca..429968d 100644
--- a/absl/synchronization/notification.h
+++ b/absl/synchronization/notification.h
@@ -22,7 +22,7 @@
// The `Notification` object maintains a private boolean "notified" state that
// transitions to `true` at most once. The `Notification` class provides the
// following primary member functions:
-// * `HasBeenNotified() `to query its state
+// * `HasBeenNotified()` to query its state
// * `WaitForNotification*()` to have threads wait until the "notified" state
// is `true`.
// * `Notify()` to set the notification's "notified" state to `true` and
diff --git a/ci/linux_gcc-latest_libstdcxx_cmake.sh b/ci/linux_gcc-latest_libstdcxx_cmake.sh
index ab06aa0..eccb381 100755
--- a/ci/linux_gcc-latest_libstdcxx_cmake.sh
+++ b/ci/linux_gcc-latest_libstdcxx_cmake.sh
@@ -54,7 +54,7 @@
cmake /abseil-cpp \
-DABSL_GOOGLETEST_DOWNLOAD_URL=${ABSL_GOOGLETEST_DOWNLOAD_URL} \
-DBUILD_SHARED_LIBS=${build_shared} \
- -DBUILD_TESTING=ON \
+ -DABSL_BUILD_TESTING=ON \
-DCMAKE_BUILD_TYPE=${compilation_mode} \
-DCMAKE_CXX_STANDARD=${std} \
-DCMAKE_MODULE_LINKER_FLAGS=\"-Wl,--no-undefined\" && \
diff --git a/ci/linux_gcc_alpine_cmake.sh b/ci/linux_gcc_alpine_cmake.sh
index bce27d2..bf2e123 100755
--- a/ci/linux_gcc_alpine_cmake.sh
+++ b/ci/linux_gcc_alpine_cmake.sh
@@ -53,7 +53,7 @@
/bin/sh -c "
cmake /abseil-cpp \
-DABSL_GOOGLETEST_DOWNLOAD_URL=${ABSL_GOOGLETEST_DOWNLOAD_URL} \
- -DBUILD_TESTING=ON \
+ -DABSL_BUILD_TESTING=ON \
-DCMAKE_BUILD_TYPE=${compilation_mode} \
-DCMAKE_CXX_STANDARD=${std} \
-DCMAKE_MODULE_LINKER_FLAGS=\"-Wl,--no-undefined\" && \
diff --git a/ci/macos_xcode_cmake.sh b/ci/macos_xcode_cmake.sh
index 2a870cf..71ea253 100755
--- a/ci/macos_xcode_cmake.sh
+++ b/ci/macos_xcode_cmake.sh
@@ -45,7 +45,7 @@
time cmake ${ABSEIL_ROOT} \
-GXcode \
-DBUILD_SHARED_LIBS=${build_shared} \
- -DBUILD_TESTING=ON \
+ -DABSL_BUILD_TESTING=ON \
-DCMAKE_BUILD_TYPE=${compilation_mode} \
-DCMAKE_CXX_STANDARD=11 \
-DCMAKE_MODULE_LINKER_FLAGS="-Wl,--no-undefined" \
diff --git a/symbols_arm64_dbg.def b/symbols_arm64_dbg.def
index b7dade3..87fdac7 100644
--- a/symbols_arm64_dbg.def
+++ b/symbols_arm64_dbg.def
@@ -437,6 +437,8 @@
??$SetEdge@$0A@@CordRepBtree@cord_internal@absl@@QEAA?AUOpResult@012@_NPEAUCordRep@12@_K@Z
??$SharedCompareImpl@VCord@absl@@@absl@@YAHAEBVCord@0@0@Z
??$SharedCompareImpl@Vstring_view@absl@@@absl@@YAHAEBVCord@0@AEBVstring_view@0@@Z
+ ??$SmallMemmove@$00@cord_internal@absl@@YAXPEADPEBD_K@Z
+ ??$SmallMemmove@$0A@@cord_internal@absl@@YAXPEADPEBD_K@Z
??$StrAppend@$$V@absl@@YAXPEAV?$basic_string@DU?$char_traits@D@__1@std@@V?$allocator@D@23@@__1@std@@AEBVAlphaNum@0@1111@Z
??$StrReplaceAll@V?$initializer_list@U?$pair@Vstring_view@absl@@V12@@__1@std@@@std@@@absl@@YA?AV?$basic_string@DU?$char_traits@D@__1@std@@V?$allocator@D@23@@__1@std@@Vstring_view@0@AEBV?$initializer_list@U?$pair@Vstring_view@absl@@V12@@__1@std@@@3@@Z
??$StrReplaceAll@V?$initializer_list@U?$pair@Vstring_view@absl@@V12@@__1@std@@@std@@@absl@@YAHAEBV?$initializer_list@U?$pair@Vstring_view@absl@@V12@@__1@std@@@std@@PEAV?$basic_string@DU?$char_traits@D@__1@std@@V?$allocator@D@23@@__1@2@@Z
@@ -2485,7 +2487,6 @@
?SleepFor@absl@@YAXVDuration@1@@Z
?SlowLock@SpinLock@base_internal@absl@@AEAAXXZ
?SlowUnlock@SpinLock@base_internal@absl@@AEAAXI@Z
- ?SmallMemmove@cord_internal@absl@@YAXPEADPEBD_K_N@Z
?SnprintF@str_format_internal@absl@@YAHPEAD_KVUntypedFormatSpecImpl@12@V?$Span@$$CBVFormatArgImpl@str_format_internal@absl@@@2@@Z
?SpinLockDelay@base_internal@absl@@YAXPEAU?$atomic@I@__1@std@@IHW4SchedulingMode@12@@Z
?SpinLockSuggestedDelayNS@base_internal@absl@@YAHH@Z
@@ -3613,7 +3614,7 @@
?set_cordz_info@InlineData@cord_internal@absl@@QEAAXPEAVCordzInfo@23@@Z
?set_cordz_mean_interval@cord_internal@absl@@YAXH@Z
?set_data@InlineRep@Cord@absl@@QEAAPEAD_K@Z
- ?set_data@InlineRep@Cord@absl@@QEAAXPEBD_K_N@Z
+ ?set_data@InlineRep@Cord@absl@@QEAAXPEBD_K@Z
?set_depth@CordRepConcat@cord_internal@absl@@QEAAXE@Z
?set_end@CordRepBtree@cord_internal@absl@@AEAAX_K@Z
?set_from_arg@InputValue@UnboundConversion@str_format_internal@absl@@QEAAXH@Z
diff --git a/symbols_x64_dbg.def b/symbols_x64_dbg.def
index 5c65dda..6820239 100644
--- a/symbols_x64_dbg.def
+++ b/symbols_x64_dbg.def
@@ -437,6 +437,8 @@
??$SetEdge@$0A@@CordRepBtree@cord_internal@absl@@QEAA?AUOpResult@012@_NPEAUCordRep@12@_K@Z
??$SharedCompareImpl@VCord@absl@@@absl@@YAHAEBVCord@0@0@Z
??$SharedCompareImpl@Vstring_view@absl@@@absl@@YAHAEBVCord@0@AEBVstring_view@0@@Z
+ ??$SmallMemmove@$00@cord_internal@absl@@YAXPEADPEBD_K@Z
+ ??$SmallMemmove@$0A@@cord_internal@absl@@YAXPEADPEBD_K@Z
??$StrAppend@$$V@absl@@YAXPEAV?$basic_string@DU?$char_traits@D@__1@std@@V?$allocator@D@23@@__1@std@@AEBVAlphaNum@0@1111@Z
??$StrReplaceAll@V?$initializer_list@U?$pair@Vstring_view@absl@@V12@@__1@std@@@std@@@absl@@YA?AV?$basic_string@DU?$char_traits@D@__1@std@@V?$allocator@D@23@@__1@std@@Vstring_view@0@AEBV?$initializer_list@U?$pair@Vstring_view@absl@@V12@@__1@std@@@3@@Z
??$StrReplaceAll@V?$initializer_list@U?$pair@Vstring_view@absl@@V12@@__1@std@@@std@@@absl@@YAHAEBV?$initializer_list@U?$pair@Vstring_view@absl@@V12@@__1@std@@@std@@PEAV?$basic_string@DU?$char_traits@D@__1@std@@V?$allocator@D@23@@__1@2@@Z
@@ -2487,7 +2489,6 @@
?SleepFor@absl@@YAXVDuration@1@@Z
?SlowLock@SpinLock@base_internal@absl@@AEAAXXZ
?SlowUnlock@SpinLock@base_internal@absl@@AEAAXI@Z
- ?SmallMemmove@cord_internal@absl@@YAXPEADPEBD_K_N@Z
?SnprintF@str_format_internal@absl@@YAHPEAD_KVUntypedFormatSpecImpl@12@V?$Span@$$CBVFormatArgImpl@str_format_internal@absl@@@2@@Z
?SpinLockDelay@base_internal@absl@@YAXPEAU?$atomic@I@__1@std@@IHW4SchedulingMode@12@@Z
?SpinLockSuggestedDelayNS@base_internal@absl@@YAHH@Z
@@ -3613,7 +3614,7 @@
?set_cordz_info@InlineData@cord_internal@absl@@QEAAXPEAVCordzInfo@23@@Z
?set_cordz_mean_interval@cord_internal@absl@@YAXH@Z
?set_data@InlineRep@Cord@absl@@QEAAPEAD_K@Z
- ?set_data@InlineRep@Cord@absl@@QEAAXPEBD_K_N@Z
+ ?set_data@InlineRep@Cord@absl@@QEAAXPEBD_K@Z
?set_depth@CordRepConcat@cord_internal@absl@@QEAAXE@Z
?set_end@CordRepBtree@cord_internal@absl@@AEAAX_K@Z
?set_from_arg@InputValue@UnboundConversion@str_format_internal@absl@@QEAAXH@Z
diff --git a/symbols_x86_dbg.def b/symbols_x86_dbg.def
index 4b47ddf..85868e2 100644
--- a/symbols_x86_dbg.def
+++ b/symbols_x86_dbg.def
@@ -435,6 +435,8 @@
??$SetEdge@$0A@@CordRepBtree@cord_internal@absl@@QAE?AUOpResult@012@_NPAUCordRep@12@I@Z
??$SharedCompareImpl@VCord@absl@@@absl@@YAHABVCord@0@0@Z
??$SharedCompareImpl@Vstring_view@absl@@@absl@@YAHABVCord@0@ABVstring_view@0@@Z
+ ??$SmallMemmove@$00@cord_internal@absl@@YAXPADPBDI@Z
+ ??$SmallMemmove@$0A@@cord_internal@absl@@YAXPADPBDI@Z
??$StrAppend@$$V@absl@@YAXPAV?$basic_string@DU?$char_traits@D@__1@std@@V?$allocator@D@23@@__1@std@@ABVAlphaNum@0@1111@Z
??$StrReplaceAll@V?$initializer_list@U?$pair@Vstring_view@absl@@V12@@__1@std@@@std@@@absl@@YA?AV?$basic_string@DU?$char_traits@D@__1@std@@V?$allocator@D@23@@__1@std@@Vstring_view@0@ABV?$initializer_list@U?$pair@Vstring_view@absl@@V12@@__1@std@@@3@@Z
??$StrReplaceAll@V?$initializer_list@U?$pair@Vstring_view@absl@@V12@@__1@std@@@std@@@absl@@YAHABV?$initializer_list@U?$pair@Vstring_view@absl@@V12@@__1@std@@@std@@PAV?$basic_string@DU?$char_traits@D@__1@std@@V?$allocator@D@23@@__1@2@@Z
@@ -2481,7 +2483,6 @@
?SleepFor@absl@@YAXVDuration@1@@Z
?SlowLock@SpinLock@base_internal@absl@@AAEXXZ
?SlowUnlock@SpinLock@base_internal@absl@@AAEXI@Z
- ?SmallMemmove@cord_internal@absl@@YAXPADPBDI_N@Z
?SnprintF@str_format_internal@absl@@YAHPADIVUntypedFormatSpecImpl@12@V?$Span@$$CBVFormatArgImpl@str_format_internal@absl@@@2@@Z
?SpinLockDelay@base_internal@absl@@YAXPAU?$atomic@I@__1@std@@IHW4SchedulingMode@12@@Z
?SpinLockSuggestedDelayNS@base_internal@absl@@YAHH@Z
@@ -3607,7 +3608,7 @@
?set_cordz_info@InlineData@cord_internal@absl@@QAEXPAVCordzInfo@23@@Z
?set_cordz_mean_interval@cord_internal@absl@@YAXH@Z
?set_data@InlineRep@Cord@absl@@QAEPADI@Z
- ?set_data@InlineRep@Cord@absl@@QAEXPBDI_N@Z
+ ?set_data@InlineRep@Cord@absl@@QAEXPBDI@Z
?set_depth@CordRepConcat@cord_internal@absl@@QAEXE@Z
?set_end@CordRepBtree@cord_internal@absl@@AAEXI@Z
?set_from_arg@InputValue@UnboundConversion@str_format_internal@absl@@QAEXH@Z