[prev in list] [next in list] [prev in thread] [next in thread]
List: cfe-commits
Subject: [PATCH] D19770: Add FixedSizeStorage to TrailingObjects; NFC
From: Hubert Tong via cfe-commits <cfe-commits () lists ! llvm ! org>
Date: 2016-04-30 22:14:38
Message-ID: differential-rev-PHID-DREV-xp6sozgjyyg5r5xxu47k-req () reviews ! llvm ! org
[Download RAW message or body]
hubert.reinterpretcast created this revision.
hubert.reinterpretcast added reviewers: rsmith, faisalv, aaron.ballman.
hubert.reinterpretcast added subscribers: nwilson, cfe-commits, llvm-commits.
This change introduces two types, `FixedSizeStorage` and `FixedSizeStorageOwner`, \
which can be used to provide stack-allocated objects with trailing objects.
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,38 @@
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<trailing_objects_internal::AlignmentCalcHelper<
+ BaseTy, TrailingTys...>::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
["D19770.55725.patch" (text/x-patch)]
Index: include/llvm/Support/TrailingObjects.h
===================================================================
--- include/llvm/Support/TrailingObjects.h
+++ include/llvm/Support/TrailingObjects.h
@@ -342,6 +342,38 @@
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<trailing_objects_internal::AlignmentCalcHelper<
+ BaseTy, TrailingTys...>::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
[Attachment #4 (text/plain)]
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic