1 /* $NetBSD: gcc_attribute_aligned.c,v 1.2 2022/01/15 14:22:03 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 /* FIXME: @4 2 + @4 2 + @4 2 + @4 8 + @4 8 + @2 (8 * 10) == 108 */ 43 /* expect+1: illegal bit-field size: 255 */ 44 unsigned int sizeof_save87: sizeof(struct save87) == 108 ? 1 : -1; 45 }; 46