blob: 8e629441b4aa529b386283435383a7ba14d49070 [file] [log] [blame]
Eric Fiselierc74a2e12017-03-04 02:04:45 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Eric Fiselierd532ddc2017-03-04 02:29:25 +000010// UNSUPPORTED: c++98, c++03
11
12// The system unwind.h on OS X provides an incorrectly aligned _Unwind_Exception
13// type. That causes these tests to fail. This XFAIL is my best attempt at
14// working around this failure.
15// XFAIL: darwin && libcxxabi-has-system-unwinder
16
Eric Fiselierc74a2e12017-03-04 02:04:45 +000017// Test that the address of the exception object is properly aligned to the
18// largest supported alignment for the system.
19
20#include <cstdint>
21#include <cassert>
22
Eric Fiselierd532ddc2017-03-04 02:29:25 +000023#include <unwind.h>
24
Eric Fiselierc74a2e12017-03-04 02:04:45 +000025struct __attribute__((aligned)) AlignedType {};
Eric Fiselierd532ddc2017-03-04 02:29:25 +000026static_assert(alignof(AlignedType) == alignof(_Unwind_Exception),
27 "_Unwind_Exception is incorrectly aligned. This test is expected to fail");
28
Eric Fiselierc74a2e12017-03-04 02:04:45 +000029struct MinAligned { };
30static_assert(alignof(MinAligned) == 1 && sizeof(MinAligned) == 1, "");
31
32int main() {
33 for (int i=0; i < 10; ++i) {
34 try {
35 throw MinAligned{};
36 } catch (MinAligned const& ref) {
37 assert(reinterpret_cast<uintptr_t>(&ref) % alignof(AlignedType) == 0);
38 }
39 }
40}