Home | History | Annotate | Line # | Download | only in lint1
gcc_attribute_aligned.c revision 1.4
      1 /*	$NetBSD: gcc_attribute_aligned.c,v 1.4 2022/08/27 21:59:41 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: error: illegal bit-field size: 255 [36] */
     44 	unsigned int sizeof_save87: sizeof(struct save87) == 108 ? 1 : -1;
     45 };
     46 
     47 
     48 void
     49 aligned_struct_member(void)
     50 {
     51 	struct aligned {
     52 		int first;
     53 		int second __attribute__((__aligned__(16)));
     54 	};
     55 
     56 	/* TODO: should be -20 instead of -8. */
     57 	/* expect+1: error: negative array dimension (-8) [20] */
     58 	typedef int ctassert[-(int)sizeof(struct aligned)];
     59 }
     60