[clang] [clang] Implement constexpr heap allocation alignments (PR #174549)

Nikolas Klauser via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 23 01:55:44 PDT 2026


================
@@ -63,30 +64,48 @@ class TypeInfoLValue {
 
 /// Symbolic representation of a dynamic allocation.
 class DynamicAllocLValue {
-  unsigned Index;
+  // lower NumAlignmentBits: alignment exponent
+  // remaining bits: allocation index incremented by one
+  // value of zero indicates distinct empty state
+  uintptr_t AlignAndIndex;
 
 public:
-  DynamicAllocLValue() : Index(0) {}
-  explicit DynamicAllocLValue(unsigned Index) : Index(Index + 1) {}
-  unsigned getIndex() { return Index - 1; }
+  DynamicAllocLValue() : AlignAndIndex(0) {}
+  explicit DynamicAllocLValue(unsigned Index, uint64_t Align) {
+    assert(Align > 0 && "Invalid alignment for DynamicAllocLValue constructor");
+    AlignAndIndex =
----------------
philnik777 wrote:

I went for using a bitfield instead and explicitly packing/unpacking in `getOpaqueValue()` and `getFromOpaqueValue()` instead. That seems more readable to me.

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


More information about the cfe-commits mailing list