Eric Fiselier | aad0594 | 2017-03-04 02:04:45 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 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 Fiselier | 7fa8331 | 2017-03-04 03:03:27 +0000 | [diff] [blame] | 10 | // UNSUPPORTED: libcxxabi-no-exceptions |
Eric Fiselier | 494247c | 2017-03-04 02:29:25 +0000 | [diff] [blame] | 11 | // 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 Rathnayake | 0a3a1a8 | 2017-04-04 14:03:54 +0000 | [diff] [blame] | 18 | // Test that the address of the exception object is properly aligned as required |
| 19 | // by the relevant ABI |
Eric Fiselier | aad0594 | 2017-03-04 02:04:45 +0000 | [diff] [blame] | 20 | |
| 21 | #include <cstdint> |
| 22 | #include <cassert> |
| 23 | |
Eric Fiselier | 494247c | 2017-03-04 02:29:25 +0000 | [diff] [blame] | 24 | #include <unwind.h> |
| 25 | |
Eric Fiselier | aad0594 | 2017-03-04 02:04:45 +0000 | [diff] [blame] | 26 | struct __attribute__((aligned)) AlignedType {}; |
Asiri Rathnayake | 0a3a1a8 | 2017-04-04 14:03:54 +0000 | [diff] [blame] | 27 | |
| 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 | |
| 36 | static_assert(alignof(_Unwind_Exception) == EXPECTED_ALIGNMENT, |
Eric Fiselier | 494247c | 2017-03-04 02:29:25 +0000 | [diff] [blame] | 37 | "_Unwind_Exception is incorrectly aligned. This test is expected to fail"); |
| 38 | |
Eric Fiselier | aad0594 | 2017-03-04 02:04:45 +0000 | [diff] [blame] | 39 | struct MinAligned { }; |
| 40 | static_assert(alignof(MinAligned) == 1 && sizeof(MinAligned) == 1, ""); |
| 41 | |
| 42 | int main() { |
| 43 | for (int i=0; i < 10; ++i) { |
| 44 | try { |
| 45 | throw MinAligned{}; |
| 46 | } catch (MinAligned const& ref) { |
Asiri Rathnayake | 0a3a1a8 | 2017-04-04 14:03:54 +0000 | [diff] [blame] | 47 | assert(reinterpret_cast<uintptr_t>(&ref) % EXPECTED_ALIGNMENT == 0); |
Eric Fiselier | aad0594 | 2017-03-04 02:04:45 +0000 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | } |