xref: /netbsd-src/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c (revision 53b02e147d4ed531c0d2a5ca9b3e8026ba3e99b5)
1 /*	$NetBSD: gcc_attribute_aligned.c,v 1.1 2021/05/02 20:44:46 rillig Exp $	*/
2 # 3 "gcc_attribute_aligned.c"
3 
4 /*
5  * Test size computations on aligned and packed structs.
6  */
7 
8 typedef unsigned short uint16_t;
9 typedef unsigned int uint32_t;
10 typedef unsigned long long uint64_t;
11 
12 /* from sys/arch/x86/include/cpu_extended_state.h */
13 
14 union fp_addr {
15 	uint64_t fa_64;
16 	struct {
17 		uint32_t fa_off;
18 		uint16_t fa_seg;
19 		uint16_t fa_opcode;
20 	} fa_32;
21 } __attribute__((packed)) __attribute__((aligned(4)));
22 
23 struct fpacc87 {
24 	uint64_t f87_mantissa;
25 	uint16_t f87_exp_sign;
26 } __attribute__((packed)) __attribute__((aligned(2)));
27 
28 struct save87 {
29 	uint16_t s87_cw __attribute__((aligned(4)));
30 	uint16_t s87_sw __attribute__((aligned(4)));
31 	uint16_t s87_tw __attribute__((aligned(4)));
32 	union fp_addr s87_ip;
33 	union fp_addr s87_dp;
34 	struct fpacc87 s87_ac[8];
35 };
36 
37 struct {
38 	unsigned int sizeof_fp_addr: sizeof(union fp_addr) == 8 ? 1 : -1;
39 
40 	unsigned int sizeof_fpacc87: sizeof(struct fpacc87) == 10 ? 1 : -1;
41 
42 	/* expect+1: illegal bit-field size: 255 *//*FIXME*/
43 	unsigned int sizeof_save87: sizeof(struct save87) == 108 ? 1 : -1;
44 };
45