i-c-e.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // RUN: %clang_cc1 %s -ffreestanding -Wno-int-to-pointer-cast -fsyntax-only -verify -pedantic -fpascal-strings -std=c99
  2. #include <stdint.h>
  3. #include <limits.h>
  4. int a() {int p; *(1 ? &p : (void*)(0 && (a(),1))) = 10;} // expected-error {{incomplete type 'void' is not assignable}}
  5. // rdar://6091492 - ?: with __builtin_constant_p as the operand is an i-c-e.
  6. int expr;
  7. char w[__builtin_constant_p(expr) ? expr : 1];
  8. char v[sizeof(__builtin_constant_p(0)) == sizeof(int) ? 1 : -1];
  9. int implicitConversion = 1.0;
  10. char floatArith[(int)(1.0+2.0)]; // expected-warning {{must be an integer constant expression}}
  11. // __builtin_constant_p as the condition of ?: allows arbitrary foldable
  12. // constants to be transmogrified into i-c-e's.
  13. char b[__builtin_constant_p((int)(1.0+2.0)) ? (int)(1.0+2.0) : -1];
  14. struct c {
  15. int a : (
  16. __builtin_constant_p((int)(1.0+2.0)) ? (int)(1.0+
  17. expr // expected-error {{expression is not an integer constant expression}}
  18. ) : -1);
  19. };
  20. void test1(int n, int* p) { *(n ? p : (void *)(7-7)) = 1; }
  21. void test2(int n, int* p) { *(n ? p : (void *)0) = 1; }
  22. char array[1024/(sizeof (long))];
  23. int x['\xBb' == (char) 187 ? 1: -1];
  24. // PR1992
  25. void func(int x)
  26. {
  27. switch (x) {
  28. case sizeof("abc"): break;
  29. case sizeof("loooong"): func(4);
  30. case sizeof("\ploooong"): func(4);
  31. }
  32. }
  33. // rdar://4213768
  34. int expr;
  35. char y[__builtin_constant_p(expr) ? -1 : 1];
  36. char z[__builtin_constant_p(4) ? 1 : -1];
  37. // Comma tests
  38. int comma1[0?1,2:3];
  39. int comma2[1||(1,2)]; // expected-warning {{use of logical '||' with constant operand}} \
  40. // expected-note {{use '|' for a bitwise operation}}
  41. int comma3[(1,2)]; // expected-warning {{size of static array must be an integer constant expression}}
  42. // Pointer + __builtin_constant_p
  43. char pbcp[__builtin_constant_p(4) ? (intptr_t)&expr : 0]; // expected-error {{variable length array declaration not allowed at file scope}}
  44. int illegaldiv1a[1 || 1/0];
  45. int illegaldiv1b[1 && 1/0]; //expected-error{{variable length array declaration not allowed at file scope}}
  46. int illegaldiv2[1/0]; // expected-error {{variable length array declaration not allowed at file scope}}
  47. int illegaldiv3[INT_MIN / -1]; // expected-error {{variable length array declaration not allowed at file scope}}
  48. // PR9262
  49. int illegaldiv4[0 / (1 / 0)]; // expected-error {{variable length array declaration not allowed at file scope}}
  50. int chooseexpr[__builtin_choose_expr(1, 1, expr)];
  51. int realop[(__real__ 4) == 4 ? 1 : -1];
  52. int imagop[(__imag__ 4) == 0 ? 1 : -1];
  53. int *PR14729 = 0 ?: 1/0; // expected-error {{not a compile-time constant}} expected-warning 3{{}}