blob: 138fb4daf461e2b657bb85e3bcf0f4e6a76c7b87 [file] [log] [blame]
Eric Fiselieraad05942017-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 Fiselier7fa83312017-03-04 03:03:27 +000010// UNSUPPORTED: libcxxabi-no-exceptions
Eric Fiselier494247c2017-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
Asiri Rathnayake0a3a1a82017-04-04 14:03:54 +000018// Test that the address of the exception object is properly aligned as required
19// by the relevant ABI
Eric Fiselieraad05942017-03-04 02:04:45 +000020
21#include <cstdint>
22#include <cassert>
23
Eric Fiselier494247c2017-03-04 02:29:25 +000024#include <unwind.h>
25
Eric Fiselieraad05942017-03-04 02:04:45 +000026struct __attribute__((aligned)) AlignedType {};
Asiri Rathnayake0a3a1a82017-04-04 14:03:54 +000027
28// EHABI : 8-byte aligned
29// Itanium: Largest supported alignment for the system
30#if defined(_LIBUNWIND_ARM_EHABI)
31# define EXPECTED_ALIGNMENT 8
32#else
33# define EXPECTED_ALIGNMENT alignof(AlignedType)
34#endif
35
36static_assert(alignof(_Unwind_Exception) == EXPECTED_ALIGNMENT,
Eric Fiselier494247c2017-03-04 02:29:25 +000037 "_Unwind_Exception is incorrectly aligned. This test is expected to fail");
38
Eric Fiselieraad05942017-03-04 02:04:45 +000039struct MinAligned { };
40static_assert(alignof(MinAligned) == 1 && sizeof(MinAligned) == 1, "");
41
42int main() {
43 for (int i=0; i < 10; ++i) {
44 try {
45 throw MinAligned{};
46 } catch (MinAligned const& ref) {
Asiri Rathnayake0a3a1a82017-04-04 14:03:54 +000047 assert(reinterpret_cast<uintptr_t>(&ref) % EXPECTED_ALIGNMENT == 0);
Eric Fiselieraad05942017-03-04 02:04:45 +000048 }
49 }
50}