blob: 960751b3b4e8cdab2e13aa76aadbd31a6cb7ba3e [file] [log] [blame]
Akira Hatanaka1089e752017-05-16 15:19:08 +00001//===---------------- 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
21struct S {
22 int a[4];
23} __attribute__((aligned));
24
25int 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 Hatanakac5158672017-05-16 18:18:03 +000031 __cxxabiv1::__cxa_free_exception(p);
Akira Hatanaka1089e752017-05-16 15:19:08 +000032#endif
33 return 0;
34}