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 // Test that the address of the exception object is properly aligned as required 13 // by the relevant ABI 14 15 #include <cstdint> 16 #include <cassert> 17 #include <__cxxabi_config.h> 18 19 #include <unwind.h> 20 21 struct __attribute__((aligned)) AlignedType {}; 22 23 // EHABI : 8-byte aligned 24 // Itanium: Largest supported alignment for the system 25 #if defined(_LIBCXXABI_ARM_EHABI) 26 # define EXPECTED_ALIGNMENT 8 27 #else 28 # define EXPECTED_ALIGNMENT alignof(AlignedType) 29 #endif 30 31 static_assert(alignof(_Unwind_Exception) == EXPECTED_ALIGNMENT, 32 "_Unwind_Exception is incorrectly aligned. This test is expected to fail"); 33 34 struct MinAligned { }; 35 static_assert(alignof(MinAligned) == 1 && sizeof(MinAligned) == 1, ""); 36 main(int,char **)37int main(int, char**) { 38 for (int i=0; i < 10; ++i) { 39 try { 40 throw MinAligned{}; 41 } catch (MinAligned const& ref) { 42 assert(reinterpret_cast<uintptr_t>(&ref) % EXPECTED_ALIGNMENT == 0); 43 } 44 } 45 46 return 0; 47 } 48