blob: 8a41f0c4206d0afaa49eb0ca6c059ac12122edcf [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 Fiselierf4313eb2017-03-04 03:03:27 +000010// UNSUPPORTED: libcxxabi-no-exceptions
Eric Fiselierd532ddc2017-03-04 02:29:25 +000011// UNSUPPORTED: c++98, c++03
12
13// The system unwind.h on OS X provides an incorrectly aligned _Unwind_Exception
14// type. That causes these tests to fail. This XFAIL is my best attempt at
15// working around this failure.
16// XFAIL: darwin && libcxxabi-has-system-unwinder
17
Eric Fiselierc74a2e12017-03-04 02:04:45 +000018// Test that the address of the exception object is properly aligned to the
19// largest supported alignment for the system.
20
21#include <cstdint>
22#include <cassert>
23
Eric Fiselierd532ddc2017-03-04 02:29:25 +000024#include <unwind.h>
25
Eric Fiselierc74a2e12017-03-04 02:04:45 +000026struct __attribute__((aligned)) AlignedType {};
Eric Fiselierd532ddc2017-03-04 02:29:25 +000027static_assert(alignof(AlignedType) == alignof(_Unwind_Exception),
28 "_Unwind_Exception is incorrectly aligned. This test is expected to fail");
29
Eric Fiselierc74a2e12017-03-04 02:04:45 +000030struct MinAligned { };
31static_assert(alignof(MinAligned) == 1 && sizeof(MinAligned) == 1, "");
32
33int main() {
34 for (int i=0; i < 10; ++i) {
35 try {
36 throw MinAligned{};
37 } catch (MinAligned const& ref) {
38 assert(reinterpret_cast<uintptr_t>(&ref) % alignof(AlignedType) == 0);
39 }
40 }
41}