llvm.org GIT mirror llvm / 775555b
[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 <typename T, int alignment> struct PickAlignment { enum { value = alignment == 0 ? alignof(T) : alignment }; }; template <typename ValueType, std::size_t Alignment> struct packed { private: struct { alignas( PickAlignment<ValueType, Alignment>::value) char buffer[sizeof(int)]; } Value; }; using ule16_t = packed<uint16_t, unaligned>; 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367329 91177308-0d34-0410-b5e6-96231b3b80d8 Michael Liao 10 months ago
1 changed file(s) with 3 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
204204
205205 template
206206 endianness Endian,
207 std::size_t Alignment>
207 std::size_t Alignment,
208 std::size_t ALIGN = PickAlignment::value>
208209 struct packed_endian_specific_integral {
209210 using value_type = ValueType;
210211 static constexpr endianness endian = Endian;
246247
247248 private:
248249 struct {
249 alignas(PickAlignment
250 alignment>::value) char buffer[sizeof(value_type)];
250 LLVM_ALIGNAS(ALIGN) char buffer[sizeof(value_type)];
251251 } Value;
252252
253253 public: