From 7d6e9d3853ee4502db9389ccb09c130c4204e304 Mon Sep 17 00:00:00 2001 From: CJ Johnson <6013273+CJ-Johnson@users.noreply.github.com> Date: Thu, 20 Mar 2025 20:47:56 -0400 Subject: [PATCH 1/7] Add unsigned to character buffers to ensure they can provide storage --- absl/cleanup/internal/cleanup.h | 2 +- absl/container/fixed_array.h | 7 ++++--- absl/container/internal/inlined_vector.h | 18 +++++++++--------- absl/flags/internal/flag.h | 5 +++-- absl/flags/internal/registry.h | 2 +- absl/functional/internal/any_invocable.h | 6 ++---- absl/synchronization/mutex_test.cc | 4 ++-- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/absl/cleanup/internal/cleanup.h b/absl/cleanup/internal/cleanup.h index 967513a85a6..4dd6f9132b9 100644 --- a/absl/cleanup/internal/cleanup.h +++ b/absl/cleanup/internal/cleanup.h @@ -88,7 +88,7 @@ class Storage { private: bool is_callback_engaged_; - alignas(Callback) char callback_buffer_[sizeof(Callback)]; + alignas(Callback) unsigned char callback_buffer_[sizeof(Callback)]; }; } // namespace cleanup_internal diff --git a/absl/container/fixed_array.h b/absl/container/fixed_array.h index b213eb13b72..c0e0e0d02db 100644 --- a/absl/container/fixed_array.h +++ b/absl/container/fixed_array.h @@ -447,7 +447,8 @@ class ABSL_ATTRIBUTE_WARN_UNUSED FixedArray { private: ABSL_ADDRESS_SANITIZER_REDZONE(redzone_begin_); - alignas(StorageElement) char buff_[sizeof(StorageElement[inline_elements])]; + alignas(StorageElement) unsigned char buff_[sizeof( + StorageElement[inline_elements])]; ABSL_ADDRESS_SANITIZER_REDZONE(redzone_end_); }; @@ -526,7 +527,7 @@ void FixedArray::NonEmptyInlinedStorage::AnnotateConstruct( data() + n); ABSL_ANNOTATE_CONTIGUOUS_CONTAINER(RedzoneBegin(), data(), data(), RedzoneBegin()); -#endif // ABSL_HAVE_ADDRESS_SANITIZER +#endif // ABSL_HAVE_ADDRESS_SANITIZER static_cast(n); // Mark used when not in asan mode } @@ -539,7 +540,7 @@ void FixedArray::NonEmptyInlinedStorage::AnnotateDestruct( RedzoneEnd()); ABSL_ANNOTATE_CONTIGUOUS_CONTAINER(RedzoneBegin(), data(), RedzoneBegin(), data()); -#endif // ABSL_HAVE_ADDRESS_SANITIZER +#endif // ABSL_HAVE_ADDRESS_SANITIZER static_cast(n); // Mark used when not in asan mode } ABSL_NAMESPACE_END diff --git a/absl/container/internal/inlined_vector.h b/absl/container/internal/inlined_vector.h index a3b14a229ac..925b6c920b4 100644 --- a/absl/container/internal/inlined_vector.h +++ b/absl/container/internal/inlined_vector.h @@ -543,7 +543,7 @@ class Storage { (std::max)(N, sizeof(Allocated) / sizeof(ValueType)); struct Inlined { - alignas(ValueType) char inlined_data[sizeof( + alignas(ValueType) unsigned char inlined_data[sizeof( ValueType[kOptimalInlinedSize])]; }; @@ -611,8 +611,8 @@ void Storage::InitFrom(const Storage& other) { template template -auto Storage::Initialize(ValueAdapter values, - SizeType new_size) -> void { +auto Storage::Initialize(ValueAdapter values, SizeType new_size) + -> void { // Only callable from constructors! ABSL_HARDENING_ASSERT(!GetIsAllocated()); ABSL_HARDENING_ASSERT(GetSize() == 0); @@ -643,8 +643,8 @@ auto Storage::Initialize(ValueAdapter values, template template -auto Storage::Assign(ValueAdapter values, - SizeType new_size) -> void { +auto Storage::Assign(ValueAdapter values, SizeType new_size) + -> void { StorageView storage_view = MakeStorageView(); AllocationTransaction allocation_tx(GetAllocator()); @@ -686,8 +686,8 @@ auto Storage::Assign(ValueAdapter values, template template -auto Storage::Resize(ValueAdapter values, - SizeType new_size) -> void { +auto Storage::Resize(ValueAdapter values, SizeType new_size) + -> void { StorageView storage_view = MakeStorageView(); Pointer const base = storage_view.data; const SizeType size = storage_view.size; @@ -872,8 +872,8 @@ auto Storage::EmplaceBackSlow(Args&&... args) -> Reference { } template -auto Storage::Erase(ConstIterator from, - ConstIterator to) -> Iterator { +auto Storage::Erase(ConstIterator from, ConstIterator to) + -> Iterator { StorageView storage_view = MakeStorageView(); auto erase_size = static_cast>(std::distance(from, to)); diff --git a/absl/flags/internal/flag.h b/absl/flags/internal/flag.h index a243b79573c..ef739e7f7a0 100644 --- a/absl/flags/internal/flag.h +++ b/absl/flags/internal/flag.h @@ -783,7 +783,7 @@ class FlagImpl final : public CommandLineFlag { // heap allocation during initialization, which is both slows program startup // and can fail. Using reserved space + placement new allows us to avoid both // problems. - alignas(absl::Mutex) mutable char data_guard_[sizeof(absl::Mutex)]; + alignas(absl::Mutex) mutable unsigned char data_guard_[sizeof(absl::Mutex)]; }; #if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic pop @@ -876,7 +876,8 @@ class FlagImplPeer { template void* FlagOps(FlagOp op, const void* v1, void* v2, void* v3) { struct AlignedSpace { - alignas(MaskedPointer::RequiredAlignment()) alignas(T) char buf[sizeof(T)]; + alignas(MaskedPointer::RequiredAlignment()) alignas( + T) unsigned char buf[sizeof(T)]; }; using Allocator = std::allocator; switch (op) { diff --git a/absl/flags/internal/registry.h b/absl/flags/internal/registry.h index 4b68c85f5c4..8ee9aae47fb 100644 --- a/absl/flags/internal/registry.h +++ b/absl/flags/internal/registry.h @@ -87,7 +87,7 @@ class RetiredFlag { } private: - alignas(kRetiredFlagObjAlignment) char buf_[kRetiredFlagObjSize]; + alignas(kRetiredFlagObjAlignment) unsigned char buf_[kRetiredFlagObjSize]; }; } // namespace flags_internal diff --git a/absl/functional/internal/any_invocable.h b/absl/functional/internal/any_invocable.h index 6bfc4d1a7dd..67d16eebdc2 100644 --- a/absl/functional/internal/any_invocable.h +++ b/absl/functional/internal/any_invocable.h @@ -174,7 +174,7 @@ union TypeErasedState { } remote; // Local-storage for the type-erased object when small and trivial enough - alignas(kAlignment) char storage[kStorageSize]; + alignas(kAlignment) unsigned char storage[kStorageSize]; }; // A typed accessor for the object in `TypeErasedState` storage @@ -363,9 +363,7 @@ class TrivialDeleter { public: explicit TrivialDeleter(std::size_t size) : size_(size) {} - void operator()(void* target) const { - ::operator delete(target, size_); - } + void operator()(void* target) const { ::operator delete(target, size_); } private: std::size_t size_; diff --git a/absl/synchronization/mutex_test.cc b/absl/synchronization/mutex_test.cc index 2dc4d7393a3..7b7ac2e549e 100644 --- a/absl/synchronization/mutex_test.cc +++ b/absl/synchronization/mutex_test.cc @@ -29,7 +29,6 @@ #include #include -#include "gtest/gtest.h" #include "absl/base/attributes.h" #include "absl/base/config.h" #include "absl/base/internal/sysinfo.h" @@ -40,6 +39,7 @@ #include "absl/synchronization/internal/thread_pool.h" #include "absl/time/clock.h" #include "absl/time/time.h" +#include "gtest/gtest.h" #ifdef ABSL_HAVE_PTHREAD_GETSCHEDPARAM #include @@ -1725,7 +1725,7 @@ TEST(Mutex, Logging) { TEST(Mutex, LoggingAddressReuse) { // Repeatedly re-create a Mutex with debug logging at the same address. ScopedInvariantDebugging scoped_debugging; - alignas(absl::Mutex) char storage[sizeof(absl::Mutex)]; + alignas(absl::Mutex) unsigned char storage[sizeof(absl::Mutex)]; auto invariant = +[](void *alive) { EXPECT_TRUE(*static_cast(alive)); }; constexpr size_t kIters = 10; From d7bc194c53f120d1b3672059d41793acb4732431 Mon Sep 17 00:00:00 2001 From: CJ Johnson <6013273+CJ-Johnson@users.noreply.github.com> Date: Thu, 20 Mar 2025 20:53:54 -0400 Subject: [PATCH 2/7] Update fixed_array.h Remove extraneous formatting changes --- absl/container/fixed_array.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/absl/container/fixed_array.h b/absl/container/fixed_array.h index c0e0e0d02db..8bf8e6cf1af 100644 --- a/absl/container/fixed_array.h +++ b/absl/container/fixed_array.h @@ -527,7 +527,7 @@ void FixedArray::NonEmptyInlinedStorage::AnnotateConstruct( data() + n); ABSL_ANNOTATE_CONTIGUOUS_CONTAINER(RedzoneBegin(), data(), data(), RedzoneBegin()); -#endif // ABSL_HAVE_ADDRESS_SANITIZER +#endif // ABSL_HAVE_ADDRESS_SANITIZER static_cast(n); // Mark used when not in asan mode } @@ -540,7 +540,7 @@ void FixedArray::NonEmptyInlinedStorage::AnnotateDestruct( RedzoneEnd()); ABSL_ANNOTATE_CONTIGUOUS_CONTAINER(RedzoneBegin(), data(), RedzoneBegin(), data()); -#endif // ABSL_HAVE_ADDRESS_SANITIZER +#endif // ABSL_HAVE_ADDRESS_SANITIZER static_cast(n); // Mark used when not in asan mode } ABSL_NAMESPACE_END From cd0ffca3a9fa4116f2483a035f6910d666e4e4b0 Mon Sep 17 00:00:00 2001 From: CJ Johnson <6013273+CJ-Johnson@users.noreply.github.com> Date: Thu, 20 Mar 2025 20:55:40 -0400 Subject: [PATCH 3/7] Update inlined_vector.h Remove extraneous formatting changes --- absl/container/internal/inlined_vector.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/absl/container/internal/inlined_vector.h b/absl/container/internal/inlined_vector.h index 925b6c920b4..75e1fb258e6 100644 --- a/absl/container/internal/inlined_vector.h +++ b/absl/container/internal/inlined_vector.h @@ -611,8 +611,8 @@ void Storage::InitFrom(const Storage& other) { template template -auto Storage::Initialize(ValueAdapter values, SizeType new_size) - -> void { +auto Storage::Assign(ValueAdapter values, + SizeType new_size) -> void { // Only callable from constructors! ABSL_HARDENING_ASSERT(!GetIsAllocated()); ABSL_HARDENING_ASSERT(GetSize() == 0); @@ -686,8 +686,8 @@ auto Storage::Assign(ValueAdapter values, SizeType new_size) template template -auto Storage::Resize(ValueAdapter values, SizeType new_size) - -> void { +auto Storage::Resize(ValueAdapter values, + SizeType new_size) -> void { StorageView storage_view = MakeStorageView(); Pointer const base = storage_view.data; const SizeType size = storage_view.size; @@ -872,8 +872,8 @@ auto Storage::EmplaceBackSlow(Args&&... args) -> Reference { } template -auto Storage::Erase(ConstIterator from, ConstIterator to) - -> Iterator { +auto Storage::Erase(ConstIterator from, + ConstIterator to) -> Iterator { StorageView storage_view = MakeStorageView(); auto erase_size = static_cast>(std::distance(from, to)); From 6792257e62eb0647d64ed0083af153f6d67f4dda Mon Sep 17 00:00:00 2001 From: CJ Johnson <6013273+CJ-Johnson@users.noreply.github.com> Date: Thu, 20 Mar 2025 20:57:30 -0400 Subject: [PATCH 4/7] Update inlined_vector.h Remove extraneous formatting changes --- absl/container/internal/inlined_vector.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/absl/container/internal/inlined_vector.h b/absl/container/internal/inlined_vector.h index 75e1fb258e6..b0d3f077e6c 100644 --- a/absl/container/internal/inlined_vector.h +++ b/absl/container/internal/inlined_vector.h @@ -611,8 +611,8 @@ void Storage::InitFrom(const Storage& other) { template template -auto Storage::Assign(ValueAdapter values, - SizeType new_size) -> void { +auto Storage::Initialize(ValueAdapter values, + SizeType new_size) -> void { // Only callable from constructors! ABSL_HARDENING_ASSERT(!GetIsAllocated()); ABSL_HARDENING_ASSERT(GetSize() == 0); @@ -643,8 +643,8 @@ auto Storage::Assign(ValueAdapter values, template template -auto Storage::Assign(ValueAdapter values, SizeType new_size) - -> void { +auto Storage::Assign(ValueAdapter values, + SizeType new_size) -> void { StorageView storage_view = MakeStorageView(); AllocationTransaction allocation_tx(GetAllocator()); From 1944198305d5ba2aaa11bb2c08bcbea1c0ca8d01 Mon Sep 17 00:00:00 2001 From: CJ Johnson <6013273+CJ-Johnson@users.noreply.github.com> Date: Thu, 20 Mar 2025 20:58:23 -0400 Subject: [PATCH 5/7] Update any_invocable.h Remove extraneous formatting changes --- absl/functional/internal/any_invocable.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/absl/functional/internal/any_invocable.h b/absl/functional/internal/any_invocable.h index 67d16eebdc2..167d947d4c5 100644 --- a/absl/functional/internal/any_invocable.h +++ b/absl/functional/internal/any_invocable.h @@ -363,7 +363,9 @@ class TrivialDeleter { public: explicit TrivialDeleter(std::size_t size) : size_(size) {} - void operator()(void* target) const { ::operator delete(target, size_); } + void operator()(void* target) const { + ::operator delete(target, size_); + } private: std::size_t size_; From ae9c1ef57a5b7f3b9c6d5c67eefca2d5aad2eb2b Mon Sep 17 00:00:00 2001 From: CJ Johnson <6013273+CJ-Johnson@users.noreply.github.com> Date: Thu, 20 Mar 2025 20:59:17 -0400 Subject: [PATCH 6/7] Update mutex_test.cc Remove extraneous formatting changes --- absl/synchronization/mutex_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/absl/synchronization/mutex_test.cc b/absl/synchronization/mutex_test.cc index 7b7ac2e549e..d8c4fdf2b38 100644 --- a/absl/synchronization/mutex_test.cc +++ b/absl/synchronization/mutex_test.cc @@ -29,6 +29,7 @@ #include #include +#include "gtest/gtest.h" #include "absl/base/attributes.h" #include "absl/base/config.h" #include "absl/base/internal/sysinfo.h" @@ -39,7 +40,6 @@ #include "absl/synchronization/internal/thread_pool.h" #include "absl/time/clock.h" #include "absl/time/time.h" -#include "gtest/gtest.h" #ifdef ABSL_HAVE_PTHREAD_GETSCHEDPARAM #include From a328c65db884cd84b232080d30b790658f429464 Mon Sep 17 00:00:00 2001 From: CJ Johnson <6013273+CJ-Johnson@users.noreply.github.com> Date: Fri, 21 Mar 2025 12:18:57 -0400 Subject: [PATCH 7/7] Remove extraneous changes --- absl/flags/internal/flag.h | 5 ++--- absl/flags/internal/registry.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/absl/flags/internal/flag.h b/absl/flags/internal/flag.h index ef739e7f7a0..a243b79573c 100644 --- a/absl/flags/internal/flag.h +++ b/absl/flags/internal/flag.h @@ -783,7 +783,7 @@ class FlagImpl final : public CommandLineFlag { // heap allocation during initialization, which is both slows program startup // and can fail. Using reserved space + placement new allows us to avoid both // problems. - alignas(absl::Mutex) mutable unsigned char data_guard_[sizeof(absl::Mutex)]; + alignas(absl::Mutex) mutable char data_guard_[sizeof(absl::Mutex)]; }; #if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic pop @@ -876,8 +876,7 @@ class FlagImplPeer { template void* FlagOps(FlagOp op, const void* v1, void* v2, void* v3) { struct AlignedSpace { - alignas(MaskedPointer::RequiredAlignment()) alignas( - T) unsigned char buf[sizeof(T)]; + alignas(MaskedPointer::RequiredAlignment()) alignas(T) char buf[sizeof(T)]; }; using Allocator = std::allocator; switch (op) { diff --git a/absl/flags/internal/registry.h b/absl/flags/internal/registry.h index 8ee9aae47fb..4b68c85f5c4 100644 --- a/absl/flags/internal/registry.h +++ b/absl/flags/internal/registry.h @@ -87,7 +87,7 @@ class RetiredFlag { } private: - alignas(kRetiredFlagObjAlignment) unsigned char buf_[kRetiredFlagObjSize]; + alignas(kRetiredFlagObjAlignment) char buf_[kRetiredFlagObjSize]; }; } // namespace flags_internal