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