From eb7c79957bd8a81ea2e86ca19806b2b4c2b186be Mon Sep 17 00:00:00 2001 From: Petr Matrix at Akamai Technologies Date: Tue, 7 Jan 2025 19:19:20 +0100 Subject: [PATCH] Gcc undefined sanitizer compilation fix. --- absl/container/flat_hash_map.h | 7 ++++--- absl/container/flat_hash_set.h | 5 +++-- absl/container/internal/hash_policy_traits.h | 4 ++-- absl/container/internal/hash_policy_traits_test.cc | 13 +++++++------ .../internal/raw_hash_set_allocator_test.cc | 5 +++-- absl/container/internal/raw_hash_set_benchmark.cc | 9 +++++---- .../internal/raw_hash_set_probe_benchmark.cc | 3 ++- absl/container/internal/raw_hash_set_test.cc | 13 +++++++------ absl/container/node_hash_map.h | 7 ++++--- absl/container/node_hash_set.h | 5 +++-- 10 files changed, 40 insertions(+), 31 deletions(-) diff --git a/absl/container/flat_hash_map.h b/absl/container/flat_hash_map.h index 735ee3424..d7310e027 100644 --- a/absl/container/flat_hash_map.h +++ b/absl/container/flat_hash_map.h @@ -34,6 +34,7 @@ #include #include +#include #include #include @@ -656,10 +657,10 @@ struct FlatHashMapPolicy { } template - static constexpr HashSlotFn get_hash_slot_fn() { + static constexpr std::optional get_hash_slot_fn() { return memory_internal::IsLayoutCompatible::value - ? &TypeErasedApplyToSlotFn - : nullptr; + ? std::optional(&TypeErasedApplyToSlotFn) + : std::nullopt; } static size_t space_used(const slot_type*) { return 0; } diff --git a/absl/container/flat_hash_set.h b/absl/container/flat_hash_set.h index b5d0f7f95..dfce1529d 100644 --- a/absl/container/flat_hash_set.h +++ b/absl/container/flat_hash_set.h @@ -34,6 +34,7 @@ #include #include +#include #include #include @@ -554,8 +555,8 @@ struct FlatHashSetPolicy { static size_t space_used(const T*) { return 0; } template - static constexpr HashSlotFn get_hash_slot_fn() { - return &TypeErasedApplyToSlotFn; + static constexpr std::optional get_hash_slot_fn() { + return std::optional(&TypeErasedApplyToSlotFn); } }; } // namespace container_internal diff --git a/absl/container/internal/hash_policy_traits.h b/absl/container/internal/hash_policy_traits.h index ad835d6fc..ee3f1ee60 100644 --- a/absl/container/internal/hash_policy_traits.h +++ b/absl/container/internal/hash_policy_traits.h @@ -160,9 +160,9 @@ struct hash_policy_traits : common_policy_traits { // silent error: the address of * will never be NULL [-Werror=address] #pragma GCC diagnostic ignored "-Waddress" #endif - return Policy::template get_hash_slot_fn() == nullptr + return !Policy::template get_hash_slot_fn().has_value() ? &hash_slot_fn_non_type_erased - : Policy::template get_hash_slot_fn(); + : Policy::template get_hash_slot_fn().value(); #if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic pop #endif diff --git a/absl/container/internal/hash_policy_traits_test.cc b/absl/container/internal/hash_policy_traits_test.cc index 2d2c7c2c3..665526353 100644 --- a/absl/container/internal/hash_policy_traits_test.cc +++ b/absl/container/internal/hash_policy_traits_test.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -46,8 +47,8 @@ struct PolicyWithoutOptionalOps { static std::function value; template - static constexpr HashSlotFn get_hash_slot_fn() { - return nullptr; + static constexpr std::optional get_hash_slot_fn() { + return std::nullopt; } }; @@ -100,8 +101,8 @@ struct PolicyNoHashFn { } template - static constexpr HashSlotFn get_hash_slot_fn() { - return nullptr; + static constexpr std::optional get_hash_slot_fn() { + return std::nullopt; } }; @@ -109,8 +110,8 @@ size_t* PolicyNoHashFn::apply_called_count; struct PolicyCustomHashFn : PolicyNoHashFn { template - static constexpr HashSlotFn get_hash_slot_fn() { - return &TypeErasedApplyToSlotFn; + static constexpr std::optional get_hash_slot_fn() { + return std::optional(&TypeErasedApplyToSlotFn); } }; diff --git a/absl/container/internal/raw_hash_set_allocator_test.cc b/absl/container/internal/raw_hash_set_allocator_test.cc index 7e7a5063d..59907895d 100644 --- a/absl/container/internal/raw_hash_set_allocator_test.cc +++ b/absl/container/internal/raw_hash_set_allocator_test.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -181,8 +182,8 @@ struct Policy { static slot_type& element(slot_type* slot) { return *slot; } template - static constexpr HashSlotFn get_hash_slot_fn() { - return nullptr; + static constexpr std::optional get_hash_slot_fn() { + return std::nullopt; } }; diff --git a/absl/container/internal/raw_hash_set_benchmark.cc b/absl/container/internal/raw_hash_set_benchmark.cc index 424b72cff..db052dae5 100644 --- a/absl/container/internal/raw_hash_set_benchmark.cc +++ b/absl/container/internal/raw_hash_set_benchmark.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -65,8 +66,8 @@ struct IntPolicy { } template - static constexpr HashSlotFn get_hash_slot_fn() { - return nullptr; + static constexpr std::optional get_hash_slot_fn() { + return std::nullopt; } }; @@ -128,8 +129,8 @@ class StringPolicy { } template - static constexpr HashSlotFn get_hash_slot_fn() { - return nullptr; + static constexpr std::optional get_hash_slot_fn() { + return std::nullopt; } }; diff --git a/absl/container/internal/raw_hash_set_probe_benchmark.cc b/absl/container/internal/raw_hash_set_probe_benchmark.cc index 8f36305d1..be46f9e7f 100644 --- a/absl/container/internal/raw_hash_set_probe_benchmark.cc +++ b/absl/container/internal/raw_hash_set_probe_benchmark.cc @@ -16,6 +16,7 @@ // distributions, all using the default hash function for swisstable. #include +#include #include // NOLINT #include @@ -73,7 +74,7 @@ struct Policy { template static constexpr auto get_hash_slot_fn() { - return nullptr; + return std::nullopt; } }; diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc index 425e22fec..486d07a76 100644 --- a/absl/container/internal/raw_hash_set_test.cc +++ b/absl/container/internal/raw_hash_set_test.cc @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -525,8 +526,8 @@ struct ValuePolicy { } template - static constexpr HashSlotFn get_hash_slot_fn() { - return nullptr; + static constexpr std::optional get_hash_slot_fn() { + return std::nullopt; } static constexpr bool soo_enabled() { return kSoo; } @@ -633,8 +634,8 @@ class StringPolicy { } template - static constexpr HashSlotFn get_hash_slot_fn() { - return nullptr; + static constexpr std::optional get_hash_slot_fn() { + return std::nullopt; } }; @@ -1116,8 +1117,8 @@ struct DecomposePolicy { } template - static constexpr HashSlotFn get_hash_slot_fn() { - return nullptr; + static constexpr std::optional get_hash_slot_fn() { + return std::nullopt; } }; diff --git a/absl/container/node_hash_map.h b/absl/container/node_hash_map.h index 127c89373..c91335e02 100644 --- a/absl/container/node_hash_map.h +++ b/absl/container/node_hash_map.h @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -659,10 +660,10 @@ class NodeHashMapPolicy static const Value& value(const value_type* elem) { return elem->second; } template - static constexpr HashSlotFn get_hash_slot_fn() { + static constexpr std::optional get_hash_slot_fn() { return memory_internal::IsLayoutCompatible::value - ? &TypeErasedDerefAndApplyToSlotFn - : nullptr; + ? std::optional(&TypeErasedDerefAndApplyToSlotFn) + : std::nullopt; } }; } // namespace container_internal diff --git a/absl/container/node_hash_set.h b/absl/container/node_hash_set.h index cffa50ec7..43f8d4c51 100644 --- a/absl/container/node_hash_set.h +++ b/absl/container/node_hash_set.h @@ -39,6 +39,7 @@ #include #include +#include #include #include "absl/algorithm/container.h" @@ -553,8 +554,8 @@ struct NodeHashSetPolicy static size_t element_space_used(const T*) { return sizeof(T); } template - static constexpr HashSlotFn get_hash_slot_fn() { - return &TypeErasedDerefAndApplyToSlotFn; + static constexpr std::optional get_hash_slot_fn() { + return std::optional(&TypeErasedDerefAndApplyToSlotFn); } }; } // namespace container_internal -- 2.45.2.windows.1