[llvm] Don't rely on undefined behavior to store how a `User` object's allocation is laid out (PR #105714)

Daniel Paoliello via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 9 17:25:02 PDT 2024


================
@@ -43,39 +43,80 @@ struct OperandTraits;
 
 class User : public Value {
   friend struct HungoffOperandTraits;
+  template <class ConstantClass> friend struct ConstantAggrKeyType;
 
   LLVM_ATTRIBUTE_ALWAYS_INLINE static void *
   allocateFixedOperandUser(size_t, unsigned, unsigned);
 
 protected:
+  // Disable the default operator new, as all subclasses must use one of the
+  // custom operators below depending on how they store their operands.
+  void *operator new(size_t Size) = delete;
+
+  /// Information about how a User object was allocated, to be passed into the
+  /// User constructor.
+  ///
+  /// DO NOT USE DIRECTLY. Use one of the `AllocMarker` structs instead.
----------------
dpaoliello wrote:

Actually, turned out to be easier than that: I moved the conversion into `AllocInfo` as constructors, so now the only way to create one is to have an `AllocMarker`.

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


More information about the llvm-commits mailing list