[compiler-rt] [NFC] [scudo] move static_asserts closer to what they relate to (PR #84257)
Florian Mayer via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 6 15:33:03 PST 2024
https://github.com/fmayer created https://github.com/llvm/llvm-project/pull/84257
None
>From 82fa73d18926871b6bdab49a17ef7d1e2ada5233 Mon Sep 17 00:00:00 2001
From: Florian Mayer <fmayer at google.com>
Date: Wed, 6 Mar 2024 15:32:52 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.4
---
compiler-rt/lib/scudo/standalone/combined.h | 16 +++++-----------
compiler-rt/lib/scudo/standalone/stack_depot.h | 4 ++++
2 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h
index fa6077384d9826..c0b2ab63327fda 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -1553,16 +1553,6 @@ class Allocator {
constexpr u32 kFramesPerStack = 16;
static_assert(isPowerOfTwo(kFramesPerStack));
- // We need StackDepot to be aligned to 8-bytes so the ring we store after
- // is correctly assigned.
- static_assert(sizeof(StackDepot) % alignof(atomic_u64) == 0);
-
- // Make sure the maximum sized StackDepot fits withint a uintptr_t to
- // simplify the overflow checking.
- static_assert(sizeof(StackDepot) + UINT32_MAX * sizeof(atomic_u64) *
- UINT32_MAX * sizeof(atomic_u32) <
- UINTPTR_MAX);
-
if (AllocationRingBufferSize > kMaxU32Pow2 / kStacksPerRingBufferEntry)
return;
u32 TabSize = static_cast<u32>(roundUpPowerOfTwo(kStacksPerRingBufferEntry *
@@ -1570,8 +1560,12 @@ class Allocator {
if (TabSize > UINT32_MAX / kFramesPerStack)
return;
u32 RingSize = static_cast<u32>(TabSize * kFramesPerStack);
- DCHECK(isPowerOfTwo(RingSize));
+ // Make sure the maximum sized StackDepot fits withint a uintptr_t to
+ // prove we don't need overflow checking for StackDepotSize.
+ static_assert(sizeof(StackDepot) + UINT32_MAX * sizeof(atomic_u64) *
+ UINT32_MAX * sizeof(atomic_u32) <
+ UINTPTR_MAX);
uptr StackDepotSize = sizeof(StackDepot) + sizeof(atomic_u64) * RingSize +
sizeof(atomic_u32) * TabSize;
MemMapT DepotMap;
diff --git a/compiler-rt/lib/scudo/standalone/stack_depot.h b/compiler-rt/lib/scudo/standalone/stack_depot.h
index 620137e44f3723..cf3cabf7085b60 100644
--- a/compiler-rt/lib/scudo/standalone/stack_depot.h
+++ b/compiler-rt/lib/scudo/standalone/stack_depot.h
@@ -199,6 +199,10 @@ class alignas(atomic_u64) StackDepot {
void enable() NO_THREAD_SAFETY_ANALYSIS { RingEndMu.unlock(); }
};
+// We need StackDepot to be aligned to 8-bytes so the ring we store after
+// is correctly assigned.
+static_assert(sizeof(StackDepot) % alignof(atomic_u64) == 0);
+
} // namespace scudo
#endif // SCUDO_STACK_DEPOT_H_
More information about the llvm-commits
mailing list