compound-sizes.c 1.8 KB

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