From 0d6615cc1911baaa53fb0141a288b2cd7c072a13 Mon Sep 17 00:00:00 2001 From: Michael Liao Date: Tue, 30 Jul 2019 16:11:48 +0000 Subject: [PATCH] [Support] Workaround a GCC 4.8 bug on constant expression evaluation. Summary: - The following stripped code trigger a gcc-4.8 bug. To work that around, move the alignment evaluation into template parameter. ``` // https://godbolt.org/z/58p5_X // enum { aligned = 0, unaligned = 1 }; template struct PickAlignment { enum { value = alignment == 0 ? alignof(T) : alignment }; }; template struct packed { private: struct { alignas( PickAlignment::value) char buffer[sizeof(int)]; } Value; }; using ule16_t = packed; ule16_t x; ``` - Also, replace `alignas` with `LLVMALIGN_AS` to improve the compiler compatibility. Reviewers: jfb Subscribers: dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65452 llvm-svn: 367329 --- llvm/include/llvm/Support/Endian.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/Support/Endian.h b/llvm/include/llvm/Support/Endian.h index b2249471e6482..e5489da130de2 100644 --- a/llvm/include/llvm/Support/Endian.h +++ b/llvm/include/llvm/Support/Endian.h @@ -205,7 +205,8 @@ namespace detail { template + std::size_t Alignment, + std::size_t ALIGN = PickAlignment::value> struct packed_endian_specific_integral { using value_type = ValueType; static constexpr endianness endian = Endian; @@ -247,8 +248,7 @@ struct packed_endian_specific_integral { private: struct { - alignas(PickAlignment::value) char buffer[sizeof(value_type)]; + LLVM_ALIGNAS(ALIGN) char buffer[sizeof(value_type)]; } Value; public: