1*c85f09ccSJohn Levon // This tests sparse "-vcompound" output.
2*c85f09ccSJohn Levon #define NULL ((void*)0)
3*c85f09ccSJohn Levon typedef unsigned int       uint32_t;
4*c85f09ccSJohn Levon typedef unsigned long long uint64_t;
5*c85f09ccSJohn Levon 
6*c85f09ccSJohn Levon // Do not list functions.
do_nothing(void)7*c85f09ccSJohn Levon static int do_nothing(void)
8*c85f09ccSJohn Levon {}
9*c85f09ccSJohn Levon 
10*c85f09ccSJohn Levon // no:
zero(void)11*c85f09ccSJohn Levon static inline int zero(void)
12*c85f09ccSJohn Levon {
13*c85f09ccSJohn Levon 	return 0 / 1;
14*c85f09ccSJohn Levon }
15*c85f09ccSJohn Levon 
16*c85f09ccSJohn Levon // no:
17*c85f09ccSJohn Levon struct inventory {
18*c85f09ccSJohn Levon 	unsigned char	description[64];
19*c85f09ccSJohn Levon 	unsigned char	department[64];
20*c85f09ccSJohn Levon 	uint32_t	dept_number;
21*c85f09ccSJohn Levon 	uint32_t	item_cost;
22*c85f09ccSJohn Levon 	uint64_t	stock_number;
23*c85f09ccSJohn Levon 	uint32_t	tally[12];	// per month
24*c85f09ccSJohn Levon };
25*c85f09ccSJohn Levon 
26*c85f09ccSJohn Levon // no
get_inv(uint64_t stocknum)27*c85f09ccSJohn Levon static struct inventory *get_inv(uint64_t stocknum)
28*c85f09ccSJohn Levon {
29*c85f09ccSJohn Levon 	return NULL;
30*c85f09ccSJohn Levon }
31*c85f09ccSJohn Levon 
32*c85f09ccSJohn Levon // no
33*c85f09ccSJohn Levon union un {
34*c85f09ccSJohn Levon 	struct inventory inv;
35*c85f09ccSJohn Levon 	unsigned char	bytes[0];
36*c85f09ccSJohn Levon };
37*c85f09ccSJohn Levon 
38*c85f09ccSJohn Levon // yes
39*c85f09ccSJohn Levon static union un un;
40*c85f09ccSJohn Levon 
41*c85f09ccSJohn Levon // yes
42*c85f09ccSJohn Levon static struct inventory	inven[100];
43*c85f09ccSJohn Levon 
44*c85f09ccSJohn Levon // no
45*c85f09ccSJohn Levon typedef struct inventory	inventory_t;
46*c85f09ccSJohn Levon 
47*c85f09ccSJohn Levon // no
48*c85f09ccSJohn Levon static struct inventory	*invptr;
49*c85f09ccSJohn Levon 
50*c85f09ccSJohn Levon // yes
51*c85f09ccSJohn Levon static inventory_t		invent[10];
52*c85f09ccSJohn Levon 
53*c85f09ccSJohn Levon // no
54*c85f09ccSJohn Levon static float		floater;
55*c85f09ccSJohn Levon static double		double_float;
56*c85f09ccSJohn Levon 
57*c85f09ccSJohn Levon // yes
58*c85f09ccSJohn Levon static float		floats[42];
59*c85f09ccSJohn Levon static double		doubles[84];
60*c85f09ccSJohn Levon 
61*c85f09ccSJohn Levon // no
main(void)62*c85f09ccSJohn Levon int main(void)
63*c85f09ccSJohn Levon {
64*c85f09ccSJohn Levon 	// no, these are not global.
65*c85f09ccSJohn Levon 	struct inventory inv[10];
66*c85f09ccSJohn Levon 	inventory_t	invt[10];
67*c85f09ccSJohn Levon 	// what about statics?
68*c85f09ccSJohn Levon 	static struct inventory invtop;
69*c85f09ccSJohn Levon 	static inventory_t inv_top;
70*c85f09ccSJohn Levon 	static uint64_t stocknums[100];
71*c85f09ccSJohn Levon 
72*c85f09ccSJohn Levon 	invptr = get_inv(42000);
73*c85f09ccSJohn Levon 	return 0;
74*c85f09ccSJohn Levon }
75*c85f09ccSJohn Levon 
76*c85f09ccSJohn Levon /*
77*c85f09ccSJohn Levon  * check-name: compound-sizes
78*c85f09ccSJohn Levon  * check-command: sparse -vcompound $file
79*c85f09ccSJohn Levon  * check-assert: _Alignof(long long) == 8
80*c85f09ccSJohn Levon  *
81*c85f09ccSJohn Levon  * check-error-start
82*c85f09ccSJohn Levon compound-sizes.c:39:17: union un static [toplevel] un: compound size 192, alignment 8
83*c85f09ccSJohn Levon compound-sizes.c:42:25: struct inventory static [toplevel] inven[100]: compound size 19200, alignment 8
84*c85f09ccSJohn Levon compound-sizes.c:51:33: struct inventory static [toplevel] [usertype] invent[10]: compound size 1920, alignment 8
85*c85f09ccSJohn Levon compound-sizes.c:58:25: float static [toplevel] floats[42]: compound size 168, alignment 4
86*c85f09ccSJohn Levon compound-sizes.c:59:25: double static [toplevel] doubles[84]: compound size 672, alignment 8
87*c85f09ccSJohn Levon  * check-error-end
88*c85f09ccSJohn Levon  */
89