hubert.reinterpretcast updated this revision to Diff 55728.
hubert.reinterpretcast added a comment.

Use AlignOf<BaseTy> instead of AlignmentCalcHelper

Since BaseTy should be aligned properly for its trailing objects, the
use of AlignmentCalcHelper is unnecessary.


http://reviews.llvm.org/D19770

Files:
  include/llvm/Support/TrailingObjects.h

Index: include/llvm/Support/TrailingObjects.h
===================================================================
--- include/llvm/Support/TrailingObjects.h
+++ include/llvm/Support/TrailingObjects.h
@@ -342,6 +342,37 @@
                        TrailingTys, size_t>::type... Counts) {
     return sizeof(BaseTy) + ParentType::additionalSizeToAllocImpl(0, 
Counts...);
   }
+
+  /// A type where its ::_ template member is suitable for use as
+  /// uninitialized storage of an object if it were allocated with the given
+  /// trailing object counts. The template arguments are similar to those of
+  /// additionalSizeToAlloc.
+  template <typename... Tys> struct FixedSizeStorage {
+    template <size_t... Counts>
+    using _ =
+        llvm::AlignedCharArray<llvm::AlignOf<BaseTy>::Alignment,
+                               totalSizeToAlloc<Tys...>(Counts...)>;
+  };
+
+  /// A type that acts as the owner for an object placed into fixed storage.
+  class FixedSizeStorageOwner {
+  public:
+    FixedSizeStorageOwner(BaseTy *p) : p(p) {}
+    ~FixedSizeStorageOwner() {
+      assert(p && "FixedSizeStorageOwner owns null?");
+      p->~BaseTy();
+    }
+
+    BaseTy *get() { return p; }
+
+  private:
+    FixedSizeStorageOwner(const FixedSizeStorageOwner &) = delete;
+    FixedSizeStorageOwner(FixedSizeStorageOwner &&) = delete;
+    FixedSizeStorageOwner &operator=(const FixedSizeStorageOwner &) = delete;
+    FixedSizeStorageOwner &operator=(FixedSizeStorageOwner &&) = delete;
+
+    BaseTy *const p;
+  };
 };
 
 } // end namespace llvm


Index: include/llvm/Support/TrailingObjects.h
===================================================================
--- include/llvm/Support/TrailingObjects.h
+++ include/llvm/Support/TrailingObjects.h
@@ -342,6 +342,37 @@
                        TrailingTys, size_t>::type... Counts) {
     return sizeof(BaseTy) + ParentType::additionalSizeToAllocImpl(0, Counts...);
   }
+
+  /// A type where its ::_ template member is suitable for use as
+  /// uninitialized storage of an object if it were allocated with the given
+  /// trailing object counts. The template arguments are similar to those of
+  /// additionalSizeToAlloc.
+  template <typename... Tys> struct FixedSizeStorage {
+    template <size_t... Counts>
+    using _ =
+        llvm::AlignedCharArray<llvm::AlignOf<BaseTy>::Alignment,
+                               totalSizeToAlloc<Tys...>(Counts...)>;
+  };
+
+  /// A type that acts as the owner for an object placed into fixed storage.
+  class FixedSizeStorageOwner {
+  public:
+    FixedSizeStorageOwner(BaseTy *p) : p(p) {}
+    ~FixedSizeStorageOwner() {
+      assert(p && "FixedSizeStorageOwner owns null?");
+      p->~BaseTy();
+    }
+
+    BaseTy *get() { return p; }
+
+  private:
+    FixedSizeStorageOwner(const FixedSizeStorageOwner &) = delete;
+    FixedSizeStorageOwner(FixedSizeStorageOwner &&) = delete;
+    FixedSizeStorageOwner &operator=(const FixedSizeStorageOwner &) = delete;
+    FixedSizeStorageOwner &operator=(FixedSizeStorageOwner &&) = delete;
+
+    BaseTy *const p;
+  };
 };
 
 } // end namespace llvm
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to