2017-03-04 10:04:45 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2019-01-19 18:56:40 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-03-04 10:04:45 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-03-04 11:03:27 +08:00
|
|
|
// UNSUPPORTED: libcxxabi-no-exceptions
|
2017-03-04 10:29:25 +08:00
|
|
|
// UNSUPPORTED: c++98, c++03
|
|
|
|
|
|
|
|
// The system unwind.h on OS X provides an incorrectly aligned _Unwind_Exception
|
|
|
|
// type. That causes these tests to fail. This XFAIL is my best attempt at
|
|
|
|
// working around this failure.
|
|
|
|
// XFAIL: darwin && libcxxabi-has-system-unwinder
|
|
|
|
|
2017-04-04 22:03:54 +08:00
|
|
|
// Test that the address of the exception object is properly aligned as required
|
|
|
|
// by the relevant ABI
|
2017-03-04 10:04:45 +08:00
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cassert>
|
2018-08-16 19:38:09 +08:00
|
|
|
#include <__cxxabi_config.h>
|
2017-03-04 10:04:45 +08:00
|
|
|
|
2017-03-04 10:29:25 +08:00
|
|
|
#include <unwind.h>
|
|
|
|
|
2017-03-04 10:04:45 +08:00
|
|
|
struct __attribute__((aligned)) AlignedType {};
|
2017-04-04 22:03:54 +08:00
|
|
|
|
|
|
|
// EHABI : 8-byte aligned
|
|
|
|
// Itanium: Largest supported alignment for the system
|
2018-08-16 19:38:09 +08:00
|
|
|
#if defined(_LIBCXXABI_ARM_EHABI)
|
2017-04-04 22:03:54 +08:00
|
|
|
# define EXPECTED_ALIGNMENT 8
|
|
|
|
#else
|
|
|
|
# define EXPECTED_ALIGNMENT alignof(AlignedType)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static_assert(alignof(_Unwind_Exception) == EXPECTED_ALIGNMENT,
|
2017-03-04 10:29:25 +08:00
|
|
|
"_Unwind_Exception is incorrectly aligned. This test is expected to fail");
|
|
|
|
|
2017-03-04 10:04:45 +08:00
|
|
|
struct MinAligned { };
|
|
|
|
static_assert(alignof(MinAligned) == 1 && sizeof(MinAligned) == 1, "");
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
for (int i=0; i < 10; ++i) {
|
|
|
|
try {
|
|
|
|
throw MinAligned{};
|
|
|
|
} catch (MinAligned const& ref) {
|
2017-04-04 22:03:54 +08:00
|
|
|
assert(reinterpret_cast<uintptr_t>(&ref) % EXPECTED_ALIGNMENT == 0);
|
2017-03-04 10:04:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|