Akira Hatanaka | 0c1016a | 2017-05-16 15:19:08 +0000 | [diff] [blame] | 1 | //===---------------- exception_object_alignment.pass.cpp -----------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Akira Hatanaka | 0c1016a | 2017-05-16 15:19:08 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Louis Dionne | 8c61114 | 2020-04-17 10:29:15 -0400 | [diff] [blame] | 9 | // UNSUPPORTED: no-exceptions |
Akira Hatanaka | 0c1016a | 2017-05-16 15:19:08 +0000 | [diff] [blame] | 10 | |
| 11 | // Check that the pointer __cxa_allocate_exception returns is aligned to the |
| 12 | // default alignment for the target architecture. |
| 13 | |
| 14 | #include <cassert> |
| 15 | #include <cstdint> |
| 16 | #include <cxxabi.h> |
| 17 | #include <type_traits> |
| 18 | #include <__cxxabi_config.h> |
| 19 | |
| 20 | struct S { |
| 21 | int a[4]; |
| 22 | } __attribute__((aligned)); |
| 23 | |
| 24 | int main() { |
| 25 | #if !defined(_LIBCXXABI_ARM_EHABI) |
| 26 | void *p = __cxxabiv1::__cxa_allocate_exception(16); |
| 27 | auto i = reinterpret_cast<uintptr_t>(p); |
| 28 | auto a = std::alignment_of<S>::value; |
| 29 | assert(i % a == 0); |
Akira Hatanaka | 7d5d9dc | 2017-05-16 18:18:03 +0000 | [diff] [blame] | 30 | __cxxabiv1::__cxa_free_exception(p); |
Akira Hatanaka | 0c1016a | 2017-05-16 15:19:08 +0000 | [diff] [blame] | 31 | #endif |
| 32 | return 0; |
| 33 | } |