Commit b9690836 by Evan Brown Committed by Copybara-Service

Move GCC uninitialized memory warning suppression into MaybeInitializedPtr.

PiperOrigin-RevId: 614701769
Change-Id: I7c2143dd467e376eb4936ef894f3413bba681419
parent d8027081
...@@ -1133,6 +1133,23 @@ struct full_soo_tag_t {}; ...@@ -1133,6 +1133,23 @@ struct full_soo_tag_t {};
// This allows us to work around an uninitialized memory warning when // This allows us to work around an uninitialized memory warning when
// constructing begin() iterators in empty hashtables. // constructing begin() iterators in empty hashtables.
union MaybeInitializedPtr { 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; void* p;
}; };
...@@ -1205,7 +1222,7 @@ class CommonFields : public CommonFieldsGenerationInfo { ...@@ -1205,7 +1222,7 @@ class CommonFields : public CommonFieldsGenerationInfo {
} }
// Note: we can't use slots() because Qt defines "slots" as a macro. // 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 { MaybeInitializedPtr slots_union() const {
// Suppress erroneous uninitialized memory errors on GCC. // Suppress erroneous uninitialized memory errors on GCC.
#if !defined(__clang__) && defined(__GNUC__) #if !defined(__clang__) && defined(__GNUC__)
...@@ -1217,7 +1234,7 @@ class CommonFields : public CommonFieldsGenerationInfo { ...@@ -1217,7 +1234,7 @@ class CommonFields : public CommonFieldsGenerationInfo {
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif #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. // The number of filled slots.
size_t size() const { return size_ >> HasInfozShift(); } size_t size() const { return size_ >> HasInfozShift(); }
...@@ -1807,7 +1824,7 @@ class HashSetResizeHelper { ...@@ -1807,7 +1824,7 @@ class HashSetResizeHelper {
} }
void* old_slots() const { void* old_slots() const {
assert(!was_soo_); 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_; } size_t old_capacity() const { return old_capacity_; }
...@@ -2313,7 +2330,7 @@ class raw_hash_set { ...@@ -2313,7 +2330,7 @@ class raw_hash_set {
const GenerationType* generation_ptr) const GenerationType* generation_ptr)
: HashSetIteratorGenerationInfo(generation_ptr), : HashSetIteratorGenerationInfo(generation_ptr),
ctrl_(ctrl), ctrl_(ctrl),
slot_(to_slot(slot.p)) { slot_(to_slot(slot.get())) {
// This assumption helps the compiler know that any non-end iterator is // This assumption helps the compiler know that any non-end iterator is
// not equal to any end iterator. // not equal to any end iterator.
ABSL_ASSUME(ctrl != nullptr); ABSL_ASSUME(ctrl != nullptr);
...@@ -3750,19 +3767,7 @@ class raw_hash_set { ...@@ -3750,19 +3767,7 @@ class raw_hash_set {
} }
slot_type* slot_array() const { slot_type* slot_array() const {
assert(!is_soo()); 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()); return static_cast<slot_type*>(common().slot_array());
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} }
slot_type* soo_slot() { slot_type* soo_slot() {
assert(is_soo()); assert(is_soo());
......
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