[PATCH] D92500: ADT: Replace guts of AlignedCharArrayUnion with std::aligned_union_t, NFC
Duncan P. N. Exon Smith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 2 12:23:05 PST 2020
dexonsmith created this revision.
Herald added a subscriber: ributzka.
Herald added a project: LLVM.
dexonsmith requested review of this revision.
Instead of computing the alignment and size of the `char` buffer in
`AlignedCharArrayUnion`, rely on the math in `std::aligned_union_t`.
Because some users of this rely on the `buffer` field existing with a
type convertible to `char *`, we can't change the field type, but we can
still avoid duplicating the logic.
A potential follow up would be to delete `AlignedCharArrayUnion` after
updating its users to use `std::aligned_union_t` directly; or if we like
our template parameters better, could update users to stop peeking
inside and then replace the definition with:
template <class T, class... T>
using AlignedCharArrayUnion = std::aligned_union_t<1, T, Ts...>;
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D92500
Files:
llvm/include/llvm/Support/AlignOf.h
Index: llvm/include/llvm/Support/AlignOf.h
===================================================================
--- llvm/include/llvm/Support/AlignOf.h
+++ llvm/include/llvm/Support/AlignOf.h
@@ -13,32 +13,10 @@
#ifndef LLVM_SUPPORT_ALIGNOF_H
#define LLVM_SUPPORT_ALIGNOF_H
-#include "llvm/Support/Compiler.h"
-#include <cstddef>
+#include <type_traits>
namespace llvm {
-namespace detail {
-
-template <typename T, typename... Ts> class AlignerImpl {
- T t;
- AlignerImpl<Ts...> rest;
- AlignerImpl() = delete;
-};
-
-template <typename T> class AlignerImpl<T> {
- T t;
- AlignerImpl() = delete;
-};
-
-template <typename T, typename... Ts> union SizerImpl {
- char arr[sizeof(T)];
- SizerImpl<Ts...> rest;
-};
-
-template <typename T> union SizerImpl<T> { char arr[sizeof(T)]; };
-} // end namespace detail
-
/// A suitably aligned and sized character array member which can hold elements
/// of any type.
///
@@ -46,8 +24,8 @@
/// `buffer` member which can be used as suitable storage for a placement new of
/// any of these types.
template <typename T, typename... Ts> struct AlignedCharArrayUnion {
- alignas(::llvm::detail::AlignerImpl<T, Ts...>) char buffer[sizeof(
- llvm::detail::SizerImpl<T, Ts...>)];
+ using AlignedUnion = std::aligned_union_t<1, T, Ts...>;
+ alignas(alignof(AlignedUnion)) char buffer[sizeof(AlignedUnion)];
};
} // end namespace llvm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92500.309030.patch
Type: text/x-patch
Size: 1398 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201202/9c29ff06/attachment.bin>
More information about the llvm-commits
mailing list