blob: df9f37b2e133706e362dfb80bdb723ac05e592eb [file] [log] [blame]
Akira Hatanaka0c1016a2017-05-16 15:19:08 +00001//===---------------- exception_object_alignment.pass.cpp -----------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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 Hatanaka0c1016a2017-05-16 15:19:08 +00006//
7//===----------------------------------------------------------------------===//
8
Louis Dionne8c611142020-04-17 10:29:15 -04009// UNSUPPORTED: no-exceptions
Akira Hatanaka0c1016a2017-05-16 15:19:08 +000010
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
20struct S {
21 int a[4];
22} __attribute__((aligned));
23
24int 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 Hatanaka7d5d9dc2017-05-16 18:18:03 +000030 __cxxabiv1::__cxa_free_exception(p);
Akira Hatanaka0c1016a2017-05-16 15:19:08 +000031#endif
32 return 0;
33}