48 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: no-exceptions10// UNSUPPORTED: c++0311 12// Test that the address of the exception object is properly aligned as required13// by the relevant ABI14 15#include <cstdint>16#include <cassert>17#include <__cxxabi_config.h>18 19#include <unwind.h>20 21struct __attribute__((aligned)) AlignedType {};22 23// EHABI : 8-byte aligned24// Itanium: Largest supported alignment for the system25#if defined(_LIBCXXABI_ARM_EHABI)26# define EXPECTED_ALIGNMENT 827#else28# define EXPECTED_ALIGNMENT alignof(AlignedType)29#endif30 31static_assert(alignof(_Unwind_Exception) == EXPECTED_ALIGNMENT,32 "_Unwind_Exception is incorrectly aligned. This test is expected to fail");33 34struct MinAligned { };35static_assert(alignof(MinAligned) == 1 && sizeof(MinAligned) == 1, "");36 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