1*eb8650a7SLouis Dionne //===----------------------------------------------------------------------===//
20c1016a3SAkira Hatanaka //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60c1016a3SAkira Hatanaka //
70c1016a3SAkira Hatanaka //===----------------------------------------------------------------------===//
80c1016a3SAkira Hatanaka 
98c61114cSLouis Dionne // UNSUPPORTED: no-exceptions
100c1016a3SAkira Hatanaka 
1160ba1fefSLouis Dionne // The situation for the alignment of exception objects is badly messed up
1260ba1fefSLouis Dionne // before macOS 10.14. The test fails on macOS 10.9 to 10.12, passes on macOS
1360ba1fefSLouis Dionne // 10.13 (no investigation done), and passes afterwards. Just mark all the OSes
1460ba1fefSLouis Dionne // before 10.14 as unsupported.
15c360553cSLouis Dionne // UNSUPPORTED: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12|13}}
1660ba1fefSLouis Dionne 
170c1016a3SAkira Hatanaka // Check that the pointer __cxa_allocate_exception returns is aligned to the
180c1016a3SAkira Hatanaka // default alignment for the target architecture.
190c1016a3SAkira Hatanaka 
200c1016a3SAkira Hatanaka #include <cassert>
210c1016a3SAkira Hatanaka #include <cstdint>
220c1016a3SAkira Hatanaka #include <cxxabi.h>
230c1016a3SAkira Hatanaka #include <type_traits>
240c1016a3SAkira Hatanaka #include <__cxxabi_config.h>
250c1016a3SAkira Hatanaka 
260c1016a3SAkira Hatanaka struct S {
270c1016a3SAkira Hatanaka   int a[4];
280c1016a3SAkira Hatanaka } __attribute__((aligned));
290c1016a3SAkira Hatanaka 
main(int,char **)30504bc07dSLouis Dionne int main(int, char**) {
310c1016a3SAkira Hatanaka #if !defined(_LIBCXXABI_ARM_EHABI)
320c1016a3SAkira Hatanaka   void *p = __cxxabiv1::__cxa_allocate_exception(16);
330c1016a3SAkira Hatanaka   auto i = reinterpret_cast<uintptr_t>(p);
340c1016a3SAkira Hatanaka   auto a = std::alignment_of<S>::value;
350c1016a3SAkira Hatanaka   assert(i % a == 0);
367d5d9dc1SAkira Hatanaka   __cxxabiv1::__cxa_free_exception(p);
370c1016a3SAkira Hatanaka #endif
380c1016a3SAkira Hatanaka   return 0;
390c1016a3SAkira Hatanaka }
40