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. That causes these tests to 14 // fail with those SDKs. 15 // FIXME: We mark the test as unsupported on Apple until we have a Lit feature 16 // representing the SDK version. 17 // UNSUPPORTED: darwin 18 19 // Test that the address of the exception object is properly aligned as required 20 // by the relevant ABI 21 22 #include <cstdint> 23 #include <cassert> 24 #include <__cxxabi_config.h> 25 26 #include <unwind.h> 27 28 struct __attribute__((aligned)) AlignedType {}; 29 30 // EHABI : 8-byte aligned 31 // Itanium: Largest supported alignment for the system 32 #if defined(_LIBCXXABI_ARM_EHABI) 33 # define EXPECTED_ALIGNMENT 8 34 #else 35 # define EXPECTED_ALIGNMENT alignof(AlignedType) 36 #endif 37 38 static_assert(alignof(_Unwind_Exception) == EXPECTED_ALIGNMENT, 39 "_Unwind_Exception is incorrectly aligned. This test is expected to fail"); 40 41 struct MinAligned { }; 42 static_assert(alignof(MinAligned) == 1 && sizeof(MinAligned) == 1, ""); 43 main(int,char **)44int main(int, char**) { 45 for (int i=0; i < 10; ++i) { 46 try { 47 throw MinAligned{}; 48 } catch (MinAligned const& ref) { 49 assert(reinterpret_cast<uintptr_t>(&ref) % EXPECTED_ALIGNMENT == 0); 50 } 51 } 52 53 return 0; 54 } 55