xref: /netbsd-src/tests/usr.bin/xlint/lint1/d_packed_structs.c (revision 2d4c92c54fdc8f0b5de41d058e1c89b1c0351f98)
1*2d4c92c5Srillig /*	$NetBSD: d_packed_structs.c,v 1.6 2023/08/05 10:00:59 rillig Exp $	*/
2aadcb6a6Srillig # 3 "d_packed_structs.c"
3aadcb6a6Srillig 
428604916Sjruoho /* packed tests */
528604916Sjruoho 
6b2baa501Srillig /* lint1-extra-flags: -X 351 */
7b2baa501Srillig 
828604916Sjruoho struct in_addr {
928604916Sjruoho 	int x;
1028604916Sjruoho };
1128604916Sjruoho struct ip_timestamp {
1228604916Sjruoho 	char ipt_code;
1328604916Sjruoho 	char ipt_len;
1428604916Sjruoho 	char ipt_ptr;
1570a1a91eSrillig 	unsigned int
1670a1a91eSrillig 	    ipt_flg: 4,
1728604916Sjruoho 	    ipt_oflw: 4;
1828604916Sjruoho 	union ipt_timestamp {
1928604916Sjruoho 		int ipt_time[1];
2028604916Sjruoho 		struct ipt_ta {
2128604916Sjruoho 			struct in_addr ipt_addr;
2228604916Sjruoho 			int ipt_time;
2328604916Sjruoho 		} ipt_ta[1]__packed;
2428604916Sjruoho 	} ipt_timestamp__packed;
2528604916Sjruoho } __packed;
2628604916Sjruoho 
2728604916Sjruoho typedef struct __packed {
2828604916Sjruoho 	int x;
2928604916Sjruoho } t;
3028604916Sjruoho 
3128604916Sjruoho struct x {
3228604916Sjruoho 	char c;
33*2d4c92c5Srillig 	long long l;
3428604916Sjruoho } __packed;
3528604916Sjruoho 
3628604916Sjruoho struct y {
3728604916Sjruoho 	char c;
38*2d4c92c5Srillig 	long long l;
3928604916Sjruoho };
4028604916Sjruoho 
4128604916Sjruoho int a[sizeof(struct y) - sizeof(struct x) - 1];
42b525fc25Srillig 
43b525fc25Srillig /* expect+1: error: negative array dimension (-9) [20] */
44b525fc25Srillig typedef int sizeof_x[-(int)sizeof(struct x)];
45b525fc25Srillig /* expect+1: error: negative array dimension (-16) [20] */
46b525fc25Srillig typedef int sizeof_y[-(int)sizeof(struct y)];
47