Akira Hatanaka | 1089e75 | 2017-05-16 15:19:08 +0000 | [diff] [blame] | 1 | //===---------------- exception_object_alignment.pass.cpp -----------------===// |
| 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 | |
| 10 | // UNSUPPORTED: libcxxabi-no-exceptions |
| 11 | |
| 12 | // Check that the pointer __cxa_allocate_exception returns is aligned to the |
| 13 | // default alignment for the target architecture. |
| 14 | |
| 15 | #include <cassert> |
| 16 | #include <cstdint> |
| 17 | #include <cxxabi.h> |
| 18 | #include <type_traits> |
| 19 | #include <__cxxabi_config.h> |
| 20 | |
| 21 | struct S { |
| 22 | int a[4]; |
| 23 | } __attribute__((aligned)); |
| 24 | |
| 25 | int main() { |
| 26 | #if !defined(_LIBCXXABI_ARM_EHABI) |
| 27 | void *p = __cxxabiv1::__cxa_allocate_exception(16); |
| 28 | auto i = reinterpret_cast<uintptr_t>(p); |
| 29 | auto a = std::alignment_of<S>::value; |
| 30 | assert(i % a == 0); |
Akira Hatanaka | c515867 | 2017-05-16 18:18:03 +0000 | [diff] [blame] | 31 | __cxxabiv1::__cxa_free_exception(p); |
Akira Hatanaka | 1089e75 | 2017-05-16 15:19:08 +0000 | [diff] [blame] | 32 | #endif |
| 33 | return 0; |
| 34 | } |