VirtualBox

source: kBuild/vendor/sed/current/gnulib-tests/test-stdalign.c@ 3613

Last change on this file since 3613 was 3611, checked in by bird, 7 months ago

vendor/sed/current: GNU sed 4.9 (sed-4.9.tar.xz sha256:6e226b732e1cd739464ad6862bd1a1aba42d7982922da7a53519631d24975181)

File size: 3.2 KB
Line 
1/* Test of <stdalign.h>.
2 Copyright 2009-2022 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Paul Eggert, inspired by Bruno Haible's test-alignof.c. */
18
19#include <config.h>
20
21#include <stddef.h>
22#include <stdint.h>
23
24#include "macros.h"
25
26typedef long double longdouble;
27typedef struct { char a[1]; } struct1;
28typedef struct { char a[2]; } struct2;
29typedef struct { char a[3]; } struct3;
30typedef struct { char a[4]; } struct4;
31
32#if (202311 <= __STDC_VERSION__ || __alignas_is_defined \
33 || 201103 <= __cplusplus)
34/* mingw can go up only to 8. 8 is all that GNU Emacs needs, so let's
35 limit the test to 8 for now. */
36# define TEST_ALIGNMENT 8
37#else
38# define alignas(alignment)
39# define TEST_ALIGNMENT 1
40#endif
41
42#define CHECK_STATIC(type) \
43 typedef struct { char slot1; type slot2; } type##_helper; \
44 static_assert (alignof (type) == offsetof (type##_helper, slot2)); \
45 const int type##_alignment = alignof (type); \
46 type alignas (TEST_ALIGNMENT) static_##type##_alignas
47
48#define CHECK_ALIGNED(var) ASSERT ((uintptr_t) &(var) % TEST_ALIGNMENT == 0)
49
50CHECK_STATIC (char);
51CHECK_STATIC (short);
52CHECK_STATIC (int);
53CHECK_STATIC (long);
54#ifdef INT64_MAX
55CHECK_STATIC (int64_t);
56#endif
57CHECK_STATIC (float);
58CHECK_STATIC (double);
59/* CHECK_STATIC (longdouble); */
60CHECK_STATIC (struct1);
61CHECK_STATIC (struct2);
62CHECK_STATIC (struct3);
63CHECK_STATIC (struct4);
64
65int
66main ()
67{
68#if defined __SUNPRO_C && __SUNPRO_C < 0x5150
69 /* Avoid a test failure due to Sun Studio Developer Bug Report #2125432. */
70 fputs ("Skipping test: known Sun C compiler bug\n", stderr);
71 return 77;
72#elif defined __HP_cc && __ia64
73 /* Avoid a test failure due to HP-UX Itanium cc bug; see:
74 https://lists.gnu.org/r/bug-gnulib/2017-03/msg00078.html */
75 fputs ("Skipping test: known HP-UX Itanium cc compiler bug\n", stderr);
76 return 77;
77#elif defined __clang__ && defined __ibmxl__
78 /* Avoid a test failure with IBM xlc 16.1. It ignores alignas (8),
79 _Alignas (8), and __attribute__ ((__aligned__ (8))). */
80 fputs ("Skipping test: known AIX XL C compiler deficiency\n", stderr);
81 return 77;
82#else
83 CHECK_ALIGNED (static_char_alignas);
84 CHECK_ALIGNED (static_short_alignas);
85 CHECK_ALIGNED (static_int_alignas);
86 CHECK_ALIGNED (static_long_alignas);
87# ifdef INT64_MAX
88 CHECK_ALIGNED (static_int64_t_alignas);
89# endif
90 CHECK_ALIGNED (static_float_alignas);
91 CHECK_ALIGNED (static_double_alignas);
92 /* CHECK_ALIGNED (static_longdouble_alignas); */
93 CHECK_ALIGNED (static_struct1_alignas);
94 CHECK_ALIGNED (static_struct2_alignas);
95 CHECK_ALIGNED (static_struct3_alignas);
96 CHECK_ALIGNED (static_struct4_alignas);
97 return 0;
98#endif
99}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette