1 //===---------------- exception_object_alignment.pass.cpp -----------------===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 // UNSUPPORTED: no-exceptions 10 11 // The situation for the alignment of exception objects is badly messed up 12 // before macOS 10.14. The test fails on macOS 10.9 to 10.12, passes on macOS 13 // 10.13 (no investigation done), and passes afterwards. Just mark all the OSes 14 // before 10.14 as unsupported. 15 // UNSUPPORTED: with_system_cxx_lib=macosx10.13 16 // UNSUPPORTED: with_system_cxx_lib=macosx10.12 17 // UNSUPPORTED: with_system_cxx_lib=macosx10.11 18 // UNSUPPORTED: with_system_cxx_lib=macosx10.10 19 // UNSUPPORTED: with_system_cxx_lib=macosx10.9 20 21 // Check that the pointer __cxa_allocate_exception returns is aligned to the 22 // default alignment for the target architecture. 23 24 #include <cassert> 25 #include <cstdint> 26 #include <cxxabi.h> 27 #include <type_traits> 28 #include <__cxxabi_config.h> 29 30 struct S { 31 int a[4]; 32 } __attribute__((aligned)); 33 34 int main(int, char**) { 35 #if !defined(_LIBCXXABI_ARM_EHABI) 36 void *p = __cxxabiv1::__cxa_allocate_exception(16); 37 auto i = reinterpret_cast<uintptr_t>(p); 38 auto a = std::alignment_of<S>::value; 39 assert(i % a == 0); 40 __cxxabiv1::__cxa_free_exception(p); 41 #endif 42 return 0; 43 } 44