Commit 672d9e0a by Abseil Team Committed by vslashg

Export of internal Abseil changes

--
d2b7a83bafb90d35b2b7d8eb4177e9d712e8d62c by Gennadiy Rozental <rogeeff@google.com>:

Introduce ABSL specific macros for detecting the usage of sanitizers.

PiperOrigin-RevId: 321687443

--
a41342cc04b1088087dda12d7272aa3835f8e36a by Evan Brown <ezb@google.com>:

Get rid of recursion in clear_and_delete().

PiperOrigin-RevId: 321583786

--
99c6d300b17f186c28867b08cc79f1e55077e88a by Evan Brown <ezb@google.com>:

Code simplification: consolidate methods to erase values/nodes.

Motivation: this will make floating storage work simpler.

- Delete erase_same_node/erase_from_leaf_node/remove_value/remove_values_ignore_children.
- Move node deletion methods inside btree_node.
- Delete three-argument move() and use transfer_n() instead.
- Note: there's still one usage of move (in btree::erase(iterator)) that could use transfer, but I think doing so would add more complexity than it's worth.

PiperOrigin-RevId: 321407673

--
c3efed6c1763190c6b3bccbede9b2989ab21b258 by Evan Brown <ezb@google.com>:

Support heterogeneous insert_or_assign, try_emplace, operator[] for btree_map.

Also do a bit of cleanup:
- Add _impl methods for insert_or_assign/try_emplace.
- Rename some hint iterator params from `position` to `hint`.

PiperOrigin-RevId: 321399557
GitOrigin-RevId: d2b7a83bafb90d35b2b7d8eb4177e9d712e8d62c
Change-Id: Ie2d0c7c3ed197c2b53d475248941392cbad20e59
parent f624790b
...@@ -154,6 +154,12 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || ...@@ -154,6 +154,12 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
#define ABSL_INTERNAL_HAS_KEYWORD(x) 0 #define ABSL_INTERNAL_HAS_KEYWORD(x) 0
#endif #endif
#ifdef __has_feature
#define ABSL_HAVE_FEATURE(f) __has_feature(f)
#else
#define ABSL_HAVE_FEATURE(f) 0
#endif
// ABSL_HAVE_TLS is defined to 1 when __thread should be supported. // ABSL_HAVE_TLS is defined to 1 when __thread should be supported.
// We assume __thread is supported on Linux when compiled with Clang or compiled // We assume __thread is supported on Linux when compiled with Clang or compiled
// against libstdc++ with _GLIBCXX_HAVE_TLS defined. // against libstdc++ with _GLIBCXX_HAVE_TLS defined.
...@@ -226,11 +232,9 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || ...@@ -226,11 +232,9 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
// * Xcode 9.3 started disallowing `thread_local` for 32-bit iOS simulator // * Xcode 9.3 started disallowing `thread_local` for 32-bit iOS simulator
// targeting iOS 9.x. // targeting iOS 9.x.
// * Xcode 10 moves the deployment target check for iOS < 9.0 to link time // * Xcode 10 moves the deployment target check for iOS < 9.0 to link time
// making __has_feature unreliable there. // making ABSL_HAVE_FEATURE unreliable there.
// //
// Otherwise, `__has_feature` is only supported by Clang so it has be inside #if ABSL_HAVE_FEATURE(cxx_thread_local) && \
// `defined(__APPLE__)` check.
#if __has_feature(cxx_thread_local) && \
!(TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0) !(TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0)
#define ABSL_HAVE_THREAD_LOCAL 1 #define ABSL_HAVE_THREAD_LOCAL 1
#endif #endif
...@@ -312,15 +316,15 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || ...@@ -312,15 +316,15 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
#if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6) #if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6)
// Clang >= 3.6 // Clang >= 3.6
#if __has_feature(cxx_exceptions) #if ABSL_HAVE_FEATURE(cxx_exceptions)
#define ABSL_HAVE_EXCEPTIONS 1 #define ABSL_HAVE_EXCEPTIONS 1
#endif // __has_feature(cxx_exceptions) #endif // ABSL_HAVE_FEATURE(cxx_exceptions)
#else #else
// Clang < 3.6 // Clang < 3.6
// http://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html#the-exceptions-macro // http://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html#the-exceptions-macro
#if defined(__EXCEPTIONS) && __has_feature(cxx_exceptions) #if defined(__EXCEPTIONS) && ABSL_HAVE_FEATURE(cxx_exceptions)
#define ABSL_HAVE_EXCEPTIONS 1 #define ABSL_HAVE_EXCEPTIONS 1
#endif // defined(__EXCEPTIONS) && __has_feature(cxx_exceptions) #endif // defined(__EXCEPTIONS) && ABSL_HAVE_FEATURE(cxx_exceptions)
#endif // __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6) #endif // __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6)
// Handle remaining special cases and default to exceptions being supported. // Handle remaining special cases and default to exceptions being supported.
...@@ -661,4 +665,50 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || ...@@ -661,4 +665,50 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
#define ABSL_DLL #define ABSL_DLL
#endif // defined(_MSC_VER) #endif // defined(_MSC_VER)
// ABSL_HAVE_MEMORY_SANITIZER
//
// MemorySanitizer (MSan) is a detector of uninitialized reads. It consists of
// 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(MEMORY_SANITIZER)
// The MEMORY_SANITIZER macro is deprecated but we will continue to honor it
// for now.
#define ABSL_HAVE_MEMORY_SANITIZER 1
#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
// ABSL_HAVE_THREAD_SANITIZER
//
// ThreadSanitizer (TSan) is a fast data race detector.
#ifdef ABSL_HAVE_THREAD_SANITIZER
#error "ABSL_HAVE_THREAD_SANITIZER cannot be directly set."
#elif defined(THREAD_SANITIZER)
// The THREAD_SANITIZER macro is deprecated but we will continue to honor it
// for now.
#define ABSL_HAVE_THREAD_SANITIZER 1
#elif defined(__SANITIZE_THREAD__)
#define ABSL_HAVE_THREAD_SANITIZER 1
#elif ABSL_HAVE_FEATURE(thread_sanitizer)
#define ABSL_HAVE_THREAD_SANITIZER 1
#endif
// ABSL_HAVE_ADDRESS_SANITIZER
//
// AddressSanitizer (ASan) is a fast memory error detector.
#ifdef ABSL_HAVE_ADDRESS_SANITIZER
#error "ABSL_HAVE_ADDRESS_SANITIZER cannot be directly set."
#elif defined(ADDRESS_SANITIZER)
// The ADDRESS_SANITIZER macro is deprecated but we will continue to honor it
// for now.
#define ABSL_HAVE_ADDRESS_SANITIZER 1
#elif defined(__SANITIZE_ADDRESS__)
#define ABSL_HAVE_ADDRESS_SANITIZER 1
#elif ABSL_HAVE_FEATURE(address_sanitizer)
#define ABSL_HAVE_ADDRESS_SANITIZER 1
#endif
#endif // ABSL_BASE_CONFIG_H_ #endif // ABSL_BASE_CONFIG_H_
...@@ -53,19 +53,9 @@ ...@@ -53,19 +53,9 @@
#include "absl/base/internal/dynamic_annotations.h" // IWYU pragma: export #include "absl/base/internal/dynamic_annotations.h" // IWYU pragma: export
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Decide which features are enabled // Decide which features are enabled.
#ifndef DYNAMIC_ANNOTATIONS_ENABLED #ifdef ABSL_HAVE_THREAD_SANITIZER
#define DYNAMIC_ANNOTATIONS_ENABLED 0
#endif
#if defined(__clang__) && !defined(SWIG)
#define ABSL_INTERNAL_IGNORE_READS_ATTRIBUTE_ENABLED 1
#else
#define ABSL_INTERNAL_IGNORE_READS_ATTRIBUTE_ENABLED 0
#endif
#if DYNAMIC_ANNOTATIONS_ENABLED != 0
#define ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED 1 #define ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED 1
#define ABSL_INTERNAL_READS_ANNOTATIONS_ENABLED 1 #define ABSL_INTERNAL_READS_ANNOTATIONS_ENABLED 1
...@@ -85,24 +75,21 @@ ...@@ -85,24 +75,21 @@
// will issue a warning, if these attributes are compiled. Only include them // will issue a warning, if these attributes are compiled. Only include them
// when compiling using Clang. // when compiling using Clang.
// ANNOTALYSIS_ENABLED == 1 when IGNORE_READ_ATTRIBUTE_ENABLED == 1 #if defined(__clang__)
#define ABSL_INTERNAL_ANNOTALYSIS_ENABLED \ #define ABSL_INTERNAL_ANNOTALYSIS_ENABLED 1
ABSL_INTERNAL_IGNORE_READS_ATTRIBUTE_ENABLED #if !defined(SWIG)
// Read/write annotations are enabled in Annotalysis mode; disabled otherwise. #define ABSL_INTERNAL_IGNORE_READS_ATTRIBUTE_ENABLED 1
#define ABSL_INTERNAL_READS_WRITES_ANNOTATIONS_ENABLED \ #else
ABSL_INTERNAL_ANNOTALYSIS_ENABLED #define ABSL_INTERNAL_IGNORE_READS_ATTRIBUTE_ENABLED 0
#endif
// Memory annotations are also made available to LLVM's Memory Sanitizer
#if defined(MEMORY_SANITIZER) && defined(__has_feature) && \
!defined(__native_client__)
#if __has_feature(memory_sanitizer)
#define ABSL_INTERNAL_MEMORY_ANNOTATIONS_ENABLED 1
#endif #endif
#else
#define ABSL_INTERNAL_ANNOTALYSIS_ENABLED 0
#define ABSL_INTERNAL_IGNORE_READS_ATTRIBUTE_ENABLED 0
#endif #endif
#ifndef ABSL_INTERNAL_MEMORY_ANNOTATIONS_ENABLED // Read/write annotations are enabled in Annotalysis mode; disabled otherwise.
#define ABSL_INTERNAL_MEMORY_ANNOTATIONS_ENABLED 0 #define ABSL_INTERNAL_READS_WRITES_ANNOTATIONS_ENABLED \
ABSL_INTERNAL_ANNOTALYSIS_ENABLED
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
...@@ -243,7 +230,7 @@ ABSL_INTERNAL_END_EXTERN_C ...@@ -243,7 +230,7 @@ ABSL_INTERNAL_END_EXTERN_C
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Define memory annotations. // Define memory annotations.
#if ABSL_INTERNAL_MEMORY_ANNOTATIONS_ENABLED == 1 #ifdef ABSL_HAVE_MEMORY_SANITIZER
#include <sanitizer/msan_interface.h> #include <sanitizer/msan_interface.h>
...@@ -253,9 +240,10 @@ ABSL_INTERNAL_END_EXTERN_C ...@@ -253,9 +240,10 @@ ABSL_INTERNAL_END_EXTERN_C
#define ABSL_ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) \ #define ABSL_ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) \
__msan_allocated_memory(address, size) __msan_allocated_memory(address, size)
#else // ABSL_INTERNAL_MEMORY_ANNOTATIONS_ENABLED == 0 #else // !defined(ABSL_HAVE_MEMORY_SANITIZER)
#if DYNAMIC_ANNOTATIONS_ENABLED == 1 // TODO(rogeeff): remove this branch
#ifdef ABSL_HAVE_THREAD_SANITIZER
#define ABSL_ANNOTATE_MEMORY_IS_INITIALIZED(address, size) \ #define ABSL_ANNOTATE_MEMORY_IS_INITIALIZED(address, size) \
do { \ do { \
(void)(address); \ (void)(address); \
...@@ -273,7 +261,7 @@ ABSL_INTERNAL_END_EXTERN_C ...@@ -273,7 +261,7 @@ ABSL_INTERNAL_END_EXTERN_C
#endif #endif
#endif // ABSL_INTERNAL_MEMORY_ANNOTATIONS_ENABLED #endif // ABSL_HAVE_MEMORY_SANITIZER
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Define IGNORE_READS_BEGIN/_END attributes. // Define IGNORE_READS_BEGIN/_END attributes.
...@@ -468,7 +456,7 @@ ABSL_INTERNAL_END_EXTERN_C ...@@ -468,7 +456,7 @@ ABSL_INTERNAL_END_EXTERN_C
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Address sanitizer annotations // Address sanitizer annotations
#ifdef ADDRESS_SANITIZER #ifdef ABSL_HAVE_ADDRESS_SANITIZER
// Describe the current state of a contiguous container such as e.g. // Describe the current state of a contiguous container such as e.g.
// std::vector or std::string. For more details see // std::vector or std::string. For more details see
// sanitizer/common_interface_defs.h, which is provided by the compiler. // sanitizer/common_interface_defs.h, which is provided by the compiler.
...@@ -483,16 +471,15 @@ ABSL_INTERNAL_END_EXTERN_C ...@@ -483,16 +471,15 @@ ABSL_INTERNAL_END_EXTERN_C
#else #else
#define ABSL_ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid) #define ABSL_ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid) // empty
#define ABSL_ADDRESS_SANITIZER_REDZONE(name) static_assert(true, "") #define ABSL_ADDRESS_SANITIZER_REDZONE(name) static_assert(true, "")
#endif // ADDRESS_SANITIZER #endif // ABSL_HAVE_ADDRESS_SANITIZER
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Undefine the macros intended only for this file. // Undefine the macros intended only for this file.
#undef ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED #undef ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED
#undef ABSL_INTERNAL_MEMORY_ANNOTATIONS_ENABLED
#undef ABSL_INTERNAL_READS_ANNOTATIONS_ENABLED #undef ABSL_INTERNAL_READS_ANNOTATIONS_ENABLED
#undef ABSL_INTERNAL_WRITES_ANNOTATIONS_ENABLED #undef ABSL_INTERNAL_WRITES_ANNOTATIONS_ENABLED
#undef ABSL_INTERNAL_ANNOTALYSIS_ENABLED #undef ABSL_INTERNAL_ANNOTALYSIS_ENABLED
......
...@@ -2509,6 +2509,39 @@ TEST(Btree, ...@@ -2509,6 +2509,39 @@ TEST(Btree,
EXPECT_THAT(m2, EXPECT_THAT(m2,
ElementsAre(Pair(IsEmpty(), 1), Pair(ElementsAre(IsNull()), 2))); ElementsAre(Pair(IsEmpty(), 1), Pair(ElementsAre(IsNull()), 2)));
} }
TEST(Btree, HeterogeneousTryEmplace) {
absl::btree_map<std::string, int> m;
std::string s = "key";
absl::string_view sv = s;
m.try_emplace(sv, 1);
EXPECT_EQ(m[s], 1);
m.try_emplace(m.end(), sv, 2);
EXPECT_EQ(m[s], 1);
}
TEST(Btree, HeterogeneousOperatorMapped) {
absl::btree_map<std::string, int> m;
std::string s = "key";
absl::string_view sv = s;
m[sv] = 1;
EXPECT_EQ(m[s], 1);
m[sv] = 2;
EXPECT_EQ(m[s], 2);
}
TEST(Btree, HeterogeneousInsertOrAssign) {
absl::btree_map<std::string, int> m;
std::string s = "key";
absl::string_view sv = s;
m.insert_or_assign(sv, 1);
EXPECT_EQ(m[s], 1);
m.insert_or_assign(m.end(), sv, 2);
EXPECT_EQ(m[s], 2);
}
#endif #endif
} // namespace } // namespace
......
...@@ -429,13 +429,6 @@ struct map_slot_policy { ...@@ -429,13 +429,6 @@ struct map_slot_policy {
std::move(src->value)); std::move(src->value));
} }
} }
template <class Allocator>
static void move(Allocator* alloc, slot_type* first, slot_type* last,
slot_type* result) {
for (slot_type *src = first, *dest = result; src != last; ++src, ++dest)
move(alloc, src, dest);
}
}; };
} // namespace container_internal } // namespace container_internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment