vla-sizeof-ice.c 422 B

1234567891011121314151617181920
  1. // credit goes to Martin Uecker for the awesome ICE_P macro
  2. #define ICE_P(x) \
  3. (__builtin_types_compatible_p(typeof(0?((void*)((long)(x)*0l)):(int*)1),int*))
  4. #define T(x) __builtin_choose_expr(ICE_P(x), 1, 0)
  5. #define TEST(x, r) _Static_assert(T(x) == r, #x " => " #r)
  6. static void test(int n)
  7. {
  8. char foo[n++];
  9. TEST(sizeof(foo), 0);
  10. }
  11. /*
  12. * check-name: vla-sizeof-ice
  13. * check-command: sparse -Wno-vla $file
  14. */