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