| //===----------------------------------------------------------------------===// | |
| // | |
| // 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 | |
| // | |
| //===----------------------------------------------------------------------===// | |
| /// | |
| /// \file | |
| /// Unit tests for jmp_buf and sigjmp_buf header layout. | |
| /// | |
| //===----------------------------------------------------------------------===// | |
| #include "test/include/jmp_buf_test.h" | |
| #include "test/UnitTest/Test.h" | |
| #if !defined(__riscv_float_abi_single) | |
| #include "include/llvm-libc-macros/offsetof-macro.h" | |
| #include "include/llvm-libc-types/__jmp_buf.h" | |
| #include "include/llvm-libc-types/jmp_buf.h" | |
| #include "include/llvm-libc-types/sigjmp_buf.h" | |
| #endif | |
| TEST(LlvmLibcJmpBufTest, ConsistentLayoutAcrossFpModes) { | |
| LIBC_NAMESPACE::JmpBufLayout nofp = LIBC_NAMESPACE::get_nofp_jmp_buf_layout(); | |
| #if !defined(__riscv_float_abi_single) | |
| EXPECT_EQ(nofp.jmp_buf_size, sizeof(jmp_buf)); | |
| EXPECT_EQ(nofp.jmp_buf_align, alignof(jmp_buf)); | |
| EXPECT_EQ(nofp.sigjmp_buf_size, sizeof(sigjmp_buf)); | |
| EXPECT_EQ(nofp.sigjmp_buf_align, alignof(sigjmp_buf)); | |
| EXPECT_EQ(sizeof(jmp_buf), sizeof(__jmp_buf)); | |
| EXPECT_EQ(sizeof(sigjmp_buf), sizeof(__jmp_buf)); | |
| #ifdef __aarch64__ | |
| EXPECT_EQ(sizeof(__jmp_buf::opaque), 14 * sizeof(long)); | |
| EXPECT_EQ(sizeof(__jmp_buf::fopaque), 8 * sizeof(long)); | |
| EXPECT_GE(sizeof(jmp_buf), 22 * sizeof(long)); | |
| #endif | |
| #if (defined(__linux__) || defined(__APPLE__)) && \ | |
| (defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) || \ | |
| defined(__arm__) || defined(__riscv)) | |
| ASSERT_TRUE(nofp.has_sigmask); | |
| EXPECT_EQ(nofp.sigmask_offset, offsetof(__jmp_buf, sigmask)); | |
| #endif | |
| #else | |
| EXPECT_EQ(nofp.jmp_buf_size, size_t(0)); | |
| EXPECT_FALSE(nofp.has_sigmask); | |
| #endif // !defined(__riscv_float_abi_single) | |
| } |