HomePhabricator

[Support] Workaround a GCC 4.8 bug on constant expression evaluation.

Authored by hliao on Jul 30 2019, 9:11 AM.

Description

[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

llvm-svn: 367329