summaryrefslogtreecommitdiff
path: root/test/test_exception_address_alignment.pass.cpp
blob: 5c5b4dfe7cca8ef1e2e9a1d24d2232f0fa18aba4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// Test that the address of the exception object is properly aligned to the
// largest supported alignment for the system.

#include <cstdint>
#include <cassert>

struct __attribute__((aligned)) AlignedType {};
struct MinAligned {  };
static_assert(alignof(MinAligned) == 1 && sizeof(MinAligned) == 1, "");

int main() {
  for (int i=0; i < 10; ++i) {
    try {
      throw MinAligned{};
    } catch (MinAligned const& ref) {
      assert(reinterpret_cast<uintptr_t>(&ref) % alignof(AlignedType) == 0);
    }
  }
}