[llvm] DynamicAPInt: optimize size of structure (PR #97831)

Arjun P via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 6 03:24:43 PDT 2024


================
@@ -203,6 +211,14 @@ class DynamicAPInt {
 
   friend hash_code hash_value(const DynamicAPInt &x); // NOLINT
 
+  void static_assert_layout() { // NOLINT
+    constexpr size_t ValLargeOff =
+        offsetof(DynamicAPInt, ValLarge.Val.BitWidth);
+    constexpr size_t ValSmallOff = offsetof(DynamicAPInt, ValSmall);
+    constexpr size_t ValSmallSz = sizeof(ValSmall);
+    static_assert(ValLargeOff >= ValSmallOff + ValSmallSz);
+  }
+
----------------
Superty wrote:

Not sure if there is some style guidance for this but I think this stuff can go directly at the namespace scope without an enclosing function. I leave it to you to pick whichever you think is better / fits guidelines

https://github.com/llvm/llvm-project/pull/97831


More information about the llvm-commits mailing list