Author: Duncan P. N. Exon Smith Date: 2020-12-02T15:56:12-08:00 New Revision: 65c5c9f92ec514ae41c8ea407d1c885737d699ec
URL: https://github.com/llvm/llvm-project/commit/65c5c9f92ec514ae41c8ea407d1c885737d699ec DIFF: https://github.com/llvm/llvm-project/commit/65c5c9f92ec514ae41c8ea407d1c885737d699ec.diff LOG: ADT: Rely on std::aligned_union_t for math in AlignedCharArrayUnion, NFC 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... Ts> using AlignedCharArrayUnion = std::aligned_union_t<1, T, Ts...>; ``` Differential Revision: https://reviews.llvm.org/D92500 Added: Modified: llvm/include/llvm/Support/AlignOf.h Removed: ################################################################################ diff --git a/llvm/include/llvm/Support/AlignOf.h b/llvm/include/llvm/Support/AlignOf.h index eb42542b777f..f9dcde4d4ff1 100644 --- a/llvm/include/llvm/Support/AlignOf.h +++ b/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 @@ template <typename T> union SizerImpl<T> { char arr[sizeof(T)]; }; /// `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 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits