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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-04-17 22:29:15 +08:00
|
|
|
// UNSUPPORTED: no-exceptions
|
2020-06-01 22:38:23 +08:00
|
|
|
// UNSUPPORTED: c++03
|
2017-03-04 10:29:25 +08:00
|
|
|
|
2020-06-06 01:06:37 +08:00
|
|
|
// The <unwind.h> header provided in the SDK of older Xcodes used to provide
|
2021-04-08 04:14:00 +08:00
|
|
|
// an incorrectly aligned _Unwind_Exception type on non-ARM. That causes these
|
2022-02-11 03:03:05 +08:00
|
|
|
// tests to fail when running against a system libc++abi and libunwind that was
|
|
|
|
// compiled with an incorrect definition of _Unwind_Exception.
|
2021-06-19 01:33:14 +08:00
|
|
|
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}}
|
2017-03-04 10:29:25 +08:00
|
|
|
|
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, "");
|
|
|
|
|
2020-10-09 01:36:33 +08:00
|
|
|
int main(int, char**) {
|
2017-03-04 10:04:45 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2020-10-09 01:36:33 +08:00
|
|
|
|
|
|
|
return 0;
|
2017-03-04 10:04:45 +08:00
|
|
|
}
|