Home | History | Annotate | Line # | Download | only in lint1
gcc_attribute_aligned.c revision 1.4
      1  1.4  rillig /*	$NetBSD: gcc_attribute_aligned.c,v 1.4 2022/08/27 21:59:41 rillig Exp $	*/
      2  1.1  rillig # 3 "gcc_attribute_aligned.c"
      3  1.1  rillig 
      4  1.1  rillig /*
      5  1.1  rillig  * Test size computations on aligned and packed structs.
      6  1.1  rillig  */
      7  1.1  rillig 
      8  1.1  rillig typedef unsigned short uint16_t;
      9  1.1  rillig typedef unsigned int uint32_t;
     10  1.1  rillig typedef unsigned long long uint64_t;
     11  1.1  rillig 
     12  1.1  rillig /* from sys/arch/x86/include/cpu_extended_state.h */
     13  1.1  rillig 
     14  1.1  rillig union fp_addr {
     15  1.1  rillig 	uint64_t fa_64;
     16  1.1  rillig 	struct {
     17  1.1  rillig 		uint32_t fa_off;
     18  1.1  rillig 		uint16_t fa_seg;
     19  1.1  rillig 		uint16_t fa_opcode;
     20  1.1  rillig 	} fa_32;
     21  1.1  rillig } __attribute__((packed)) __attribute__((aligned(4)));
     22  1.1  rillig 
     23  1.1  rillig struct fpacc87 {
     24  1.1  rillig 	uint64_t f87_mantissa;
     25  1.1  rillig 	uint16_t f87_exp_sign;
     26  1.1  rillig } __attribute__((packed)) __attribute__((aligned(2)));
     27  1.1  rillig 
     28  1.1  rillig struct save87 {
     29  1.1  rillig 	uint16_t s87_cw __attribute__((aligned(4)));
     30  1.1  rillig 	uint16_t s87_sw __attribute__((aligned(4)));
     31  1.1  rillig 	uint16_t s87_tw __attribute__((aligned(4)));
     32  1.1  rillig 	union fp_addr s87_ip;
     33  1.1  rillig 	union fp_addr s87_dp;
     34  1.1  rillig 	struct fpacc87 s87_ac[8];
     35  1.1  rillig };
     36  1.1  rillig 
     37  1.1  rillig struct {
     38  1.1  rillig 	unsigned int sizeof_fp_addr: sizeof(union fp_addr) == 8 ? 1 : -1;
     39  1.1  rillig 
     40  1.1  rillig 	unsigned int sizeof_fpacc87: sizeof(struct fpacc87) == 10 ? 1 : -1;
     41  1.1  rillig 
     42  1.2  rillig 	/* FIXME: @4 2 + @4 2 + @4 2 + @4 8 + @4 8 + @2 (8 * 10) == 108 */
     43  1.3  rillig 	/* expect+1: error: illegal bit-field size: 255 [36] */
     44  1.1  rillig 	unsigned int sizeof_save87: sizeof(struct save87) == 108 ? 1 : -1;
     45  1.1  rillig };
     46  1.4  rillig 
     47  1.4  rillig 
     48  1.4  rillig void
     49  1.4  rillig aligned_struct_member(void)
     50  1.4  rillig {
     51  1.4  rillig 	struct aligned {
     52  1.4  rillig 		int first;
     53  1.4  rillig 		int second __attribute__((__aligned__(16)));
     54  1.4  rillig 	};
     55  1.4  rillig 
     56  1.4  rillig 	/* TODO: should be -20 instead of -8. */
     57  1.4  rillig 	/* expect+1: error: negative array dimension (-8) [20] */
     58  1.4  rillig 	typedef int ctassert[-(int)sizeof(struct aligned)];
     59  1.4  rillig }
     60