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