1 /* Check jmp_buf sizes, alignments and offsets.
2    Copyright (C) 2021-2022 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4 
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9 
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14 
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <https://www.gnu.org/licenses/>.  */
18 
19 #include <stddef.h>
20 #include <setjmp.h>
21 #include <jmp_buf-macros.h>
22 
23 #define SJSTR_HELPER(x) #x
24 #define SJSTR(x) SJSTR_HELPER(x)
25 
26 #define TEST_SIZE(type, size) \
27   _Static_assert (sizeof (type) == size, \
28 		  "size of " #type " != " \
29 		  SJSTR (size))
30 #define TEST_ALIGN(type, align) \
31   _Static_assert (__alignof__ (type) == align , \
32 		  "align of " #type " != " \
33 		  SJSTR (align))
34 #define TEST_OFFSET(type, member, offset) \
35   _Static_assert (offsetof (type, member) == offset, \
36 		  "offset of " #member " field of " #type " != " \
37 		  SJSTR (offset))
38 
39 /* Check if jmp_buf have the expected sizes.  */
40 TEST_SIZE (jmp_buf, JMP_BUF_SIZE);
41 TEST_SIZE (sigjmp_buf, SIGJMP_BUF_SIZE);
42 
43 /* Check if jmp_buf have the expected alignments.  */
44 TEST_ALIGN (jmp_buf, JMP_BUF_ALIGN);
45 TEST_ALIGN (sigjmp_buf, SIGJMP_BUF_ALIGN);
46 
47 /* Check if internal fields in jmp_buf have the expected offsets.  */
48 TEST_OFFSET (struct __jmp_buf_tag, __mask_was_saved,
49 	     MASK_WAS_SAVED_OFFSET);
50 TEST_OFFSET (struct __jmp_buf_tag, __saved_mask,
51 	     SAVED_MASK_OFFSET);
52 
53 int
main(int argc,char * argv[])54 main (int argc, char *argv[])
55 {
56   return 0;
57 }
58