From 72895656c7582d3d5007dac363d877f0bd1a0c67 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Fri, 13 Jan 2017 01:13:10 +0000 Subject: [PATCH] Revert r291503, "Lift the 10-type limit for AlignedCharArrayUnion", and followings. r291503, "Lift the 10-type limit for AlignedCharArrayUnion" r291514, "Fix MSVC build of AlignedCharArrayUnion" r291515, "Revert the attempt to optimize the constexpr functions. MSVC does not handle this yet" r291519, "Try once again to fix the MSVC build of AlignedCharArrayUnion" They has been failing on i686-linux. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291875 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/AlignOf.h | 52 ++++++++++++++++++------------- unittests/Support/AlignOfTest.cpp | 18 ----------- 2 files changed, 30 insertions(+), 40 deletions(-) diff --git a/include/llvm/Support/AlignOf.h b/include/llvm/Support/AlignOf.h index 2d8297ee87d..abd19afa22f 100644 --- a/include/llvm/Support/AlignOf.h +++ b/include/llvm/Support/AlignOf.h @@ -102,37 +102,45 @@ LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(128) #endif // _MSC_VER -// This code implements the equivalent of std::aligned_union from C++11. -// That is supported by Visual Studio 2015 and GCC 5.1. -// Once these are the baselines for LLVM, we can use std::aligned_union instead. - -namespace support { namespace detail { -template constexpr size_t aligner() { return alignof(T1); } +template +class AlignerImpl { + T1 t1; T2 t2; T3 t3; T4 t4; T5 t5; T6 t6; T7 t7; T8 t8; T9 t9; T10 t10; -template constexpr size_t aligner() { - return (alignof(T1) > aligner()) ? alignof(T1) - : aligner(); -} + AlignerImpl() = delete; +}; -template constexpr size_t sizer() { return sizeof(T1); } - -template constexpr size_t sizer() { - return (sizeof(T1) > sizer()) ? sizeof(T1) : sizer(); -} +template +union SizerImpl { + char arr1[sizeof(T1)], arr2[sizeof(T2)], arr3[sizeof(T3)], arr4[sizeof(T4)], + arr5[sizeof(T5)], arr6[sizeof(T6)], arr7[sizeof(T7)], arr8[sizeof(T8)], + arr9[sizeof(T9)], arr10[sizeof(T10)]; +}; } // end namespace detail -} // end namespace support /// \brief This union template exposes a suitably aligned and sized character -/// array member which can hold elements of any of a number of types. +/// array member which can hold elements of any of up to ten types. /// /// These types may be arrays, structs, or any other types. The goal is to /// expose a char array buffer member which can be used as suitable storage for -/// a placement new of any of these types. -template -struct AlignedCharArrayUnion - : llvm::AlignedCharArray(), - support::detail::sizer()> {}; +/// a placement new of any of these types. Support for more than ten types can +/// be added at the cost of more boilerplate. +template +struct AlignedCharArrayUnion : llvm::AlignedCharArray< + alignof(llvm::detail::AlignerImpl), + sizeof(::llvm::detail::SizerImpl)> { +}; } // end namespace llvm #endif // LLVM_SUPPORT_ALIGNOF_H diff --git a/unittests/Support/AlignOfTest.cpp b/unittests/Support/AlignOfTest.cpp index dfcdc1484b3..388ca11b776 100644 --- a/unittests/Support/AlignOfTest.cpp +++ b/unittests/Support/AlignOfTest.cpp @@ -91,24 +91,6 @@ V8::~V8() {} template struct T { M m; }; -typedef uint8_t t1; -typedef uint16_t t2; -typedef uint32_t t3; -typedef uint64_t t4; -typedef int8_t t5; -typedef int16_t t6; -typedef int32_t t7; -typedef int64_t t8; -typedef struct { uint8_t bytes[16]; } t9; -typedef struct { uint16_t words[16]; } t10; -typedef struct { uint32_t words[16]; } t11; -typedef struct { uint64_t words[16]; } t12; - -typedef AlignedCharArrayUnion U; - -static_assert(sizeof(U) == sizeof(uint64_t[16]), "Statically-computed size must be right"); -static_assert(alignof(U) == alignof(uint64_t), "Statically-computed alignment must be right"); - TEST(AlignOfTest, BasicAlignedArray) { EXPECT_LE(1u, alignof(AlignedCharArrayUnion)); EXPECT_LE(2u, alignof(AlignedCharArrayUnion));