1 //===----------------------------------------------------------------------===// 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 // UNSUPPORTED: c++03 11 12 // The <unwind.h> header provided in the SDK of older Xcodes used to provide 13 // an incorrectly aligned _Unwind_Exception type on non-ARM. That causes these 14 // tests to fail when compiling against such a SDK, or when running against a 15 // system libc++abi that was compiled with an incorrect definition of _Unwind_Exception. 16 // XFAIL: apple-clang-12.0.0 && !target-arm 17 // XFAIL: apple-clang-11 && !target-arm 18 // XFAIL: apple-clang-10 && !target-arm 19 // XFAIL: apple-clang-9 && !target-arm 20 // XFAIL: with_system_cxx_lib=macosx10.12 21 // XFAIL: with_system_cxx_lib=macosx10.11 22 // XFAIL: with_system_cxx_lib=macosx10.10 23 // XFAIL: with_system_cxx_lib=macosx10.9 24 25 // Test that the address of the exception object is properly aligned as required 26 // by the relevant ABI 27 28 #include <cstdint> 29 #include <cassert> 30 #include <__cxxabi_config.h> 31 32 #include <unwind.h> 33 34 struct __attribute__((aligned)) AlignedType {}; 35 36 // EHABI : 8-byte aligned 37 // Itanium: Largest supported alignment for the system 38 #if defined(_LIBCXXABI_ARM_EHABI) 39 # define EXPECTED_ALIGNMENT 8 40 #else 41 # define EXPECTED_ALIGNMENT alignof(AlignedType) 42 #endif 43 44 static_assert(alignof(_Unwind_Exception) == EXPECTED_ALIGNMENT, 45 "_Unwind_Exception is incorrectly aligned. This test is expected to fail"); 46 47 struct MinAligned { }; 48 static_assert(alignof(MinAligned) == 1 && sizeof(MinAligned) == 1, ""); 49 50 int main(int, char**) { 51 for (int i=0; i < 10; ++i) { 52 try { 53 throw MinAligned{}; 54 } catch (MinAligned const& ref) { 55 assert(reinterpret_cast<uintptr_t>(&ref) % EXPECTED_ALIGNMENT == 0); 56 } 57 } 58 59 return 0; 60 } 61