]> granicus.if.org Git - llvm/commit
[Support] Workaround a GCC 4.8 bug on constant expression evaluation.
authorMichael Liao <michael.hliao@gmail.com>
Tue, 30 Jul 2019 16:11:48 +0000 (16:11 +0000)
committerMichael Liao <michael.hliao@gmail.com>
Tue, 30 Jul 2019 16:11:48 +0000 (16:11 +0000)
commit775555b44fce09a7ef51f8a2435b45c25b75753f
tree7822e8672cc7101d95a96d620dda32a30e7c1490
parent5093e0a4be370b21f4a74540e8d8af73768e369f
[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
include/llvm/Support/Endian.h