aboutsummaryrefslogtreecommitdiff
path: root/absl/container
diff options
context:
space:
mode:
authorEvan Brown <ezb@google.com>2024-03-11 09:59:17 -0700
committerCopybara-Service <copybara-worker@google.com>2024-03-11 10:00:31 -0700
commitb9690836ac18bb85b9ae44db3ca328131281a848 (patch)
tree454ac16ff5964eede79484b1e9cbc02c78739d00 /absl/container
parentd802708117c6ef6b9783efe499b2a2d0d0536c77 (diff)
downloadabseil-b9690836ac18bb85b9ae44db3ca328131281a848.tar.gz
abseil-b9690836ac18bb85b9ae44db3ca328131281a848.tar.bz2
abseil-b9690836ac18bb85b9ae44db3ca328131281a848.zip
Move GCC uninitialized memory warning suppression into MaybeInitializedPtr.
PiperOrigin-RevId: 614701769 Change-Id: I7c2143dd467e376eb4936ef894f3413bba681419
Diffstat (limited to 'absl/container')
-rw-r--r--absl/container/internal/raw_hash_set.h37
1 files changed, 21 insertions, 16 deletions
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h
index 81f99366..750f51ef 100644
--- a/absl/container/internal/raw_hash_set.h
+++ b/absl/container/internal/raw_hash_set.h
@@ -1133,6 +1133,23 @@ struct full_soo_tag_t {};
// This allows us to work around an uninitialized memory warning when
// constructing begin() iterators in empty hashtables.
union MaybeInitializedPtr {
+ void* get() const {
+ // Suppress erroneous uninitialized memory errors on GCC. GCC thinks that
+ // the call to slot_array() in find_or_prepare_insert() is reading
+ // uninitialized memory, but slot_array is only called there when the table
+ // is non-empty and this memory is initialized when the table is non-empty.
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#pragma GCC diagnostic ignored "-Wuninitialized"
+#endif
+ return p;
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+ }
+ void set(void* ptr) { p = ptr; }
+
void* p;
};
@@ -1205,7 +1222,7 @@ class CommonFields : public CommonFieldsGenerationInfo {
}
// Note: we can't use slots() because Qt defines "slots" as a macro.
- void* slot_array() const { return heap_or_soo_.heap.slot_array.p; }
+ void* slot_array() const { return heap_or_soo_.heap.slot_array.get(); }
MaybeInitializedPtr slots_union() const {
// Suppress erroneous uninitialized memory errors on GCC.
#if !defined(__clang__) && defined(__GNUC__)
@@ -1217,7 +1234,7 @@ class CommonFields : public CommonFieldsGenerationInfo {
#pragma GCC diagnostic pop
#endif
}
- void set_slots(void* s) { heap_or_soo_.heap.slot_array.p = s; }
+ void set_slots(void* s) { heap_or_soo_.heap.slot_array.set(s); }
// The number of filled slots.
size_t size() const { return size_ >> HasInfozShift(); }
@@ -1807,7 +1824,7 @@ class HashSetResizeHelper {
}
void* old_slots() const {
assert(!was_soo_);
- return old_heap_or_soo_.heap.slot_array.p;
+ return old_heap_or_soo_.heap.slot_array.get();
}
size_t old_capacity() const { return old_capacity_; }
@@ -2313,7 +2330,7 @@ class raw_hash_set {
const GenerationType* generation_ptr)
: HashSetIteratorGenerationInfo(generation_ptr),
ctrl_(ctrl),
- slot_(to_slot(slot.p)) {
+ slot_(to_slot(slot.get())) {
// This assumption helps the compiler know that any non-end iterator is
// not equal to any end iterator.
ABSL_ASSUME(ctrl != nullptr);
@@ -3750,19 +3767,7 @@ class raw_hash_set {
}
slot_type* slot_array() const {
assert(!is_soo());
- // Suppress erroneous uninitialized memory errors on GCC. GCC thinks that
- // the call to slot_array() in find_or_prepare_insert() is reading
- // uninitialized memory, but slot_array is only called there when the table
- // is non-empty and this memory is initialized when the table is non-empty.
-#if !defined(__clang__) && defined(__GNUC__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
-#pragma GCC diagnostic ignored "-Wuninitialized"
-#endif
return static_cast<slot_type*>(common().slot_array());
-#if !defined(__clang__) && defined(__GNUC__)
-#pragma GCC diagnostic pop
-#endif
}
slot_type* soo_slot() {
assert(is_soo());