llvm-project
47 строк · 1.3 Кб
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
21struct __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 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**) {38for (int i=0; i < 10; ++i) {39try {40throw MinAligned{};41} catch (MinAligned const& ref) {42assert(reinterpret_cast<uintptr_t>(&ref) % EXPECTED_ALIGNMENT == 0);43}44}45
46return 0;47}
48