Home | History | Annotate | Download | only in Sema
      1 // RUN: %clang_cc1 -fsyntax-only -verify %s
      2 
      3 #define EVAL_EXPR(testno, expr) int test##testno = sizeof(struct{char qq[expr];});
      4 int x;
      5 EVAL_EXPR(1, (_Bool)&x)
      6 EVAL_EXPR(2, (int)(1.0+(double)4))
      7 EVAL_EXPR(3, (int)(1.0+(float)4.0))
      8 EVAL_EXPR(4, (_Bool)(1 ? (void*)&x : 0))
      9 EVAL_EXPR(5, (_Bool)(int[]){0})
     10 struct y {int x,y;};
     11 EVAL_EXPR(6, (int)(1+(struct y*)0))
     12 EVAL_EXPR(7, (int)&((struct y*)0)->y)
     13 EVAL_EXPR(8, (_Bool)"asdf")
     14 EVAL_EXPR(9, !!&x)
     15 EVAL_EXPR(10, ((void)1, 12))
     16 void g0(void);
     17 EVAL_EXPR(11, (g0(), 12)) // FIXME: This should give an error
     18 EVAL_EXPR(12, 1.0&&2.0)
     19 EVAL_EXPR(13, x || 3.0)
     20 
     21 unsigned int l_19 = 1;
     22 EVAL_EXPR(14, (1 ^ l_19) && 1); // expected-error {{fields must have a constant size}}
     23 
     24 void f()
     25 {
     26   int a;
     27   EVAL_EXPR(15, (_Bool)&a); // expected-error {{fields must have a constant size}}
     28 }
     29 
     30 // FIXME: Turn into EVAL_EXPR test once we have more folding.
     31 _Complex float g16 = (1.0f + 1.0fi);
     32 
     33 // ?: in constant expressions.
     34 int g17[(3?:1) - 2];
     35 
     36 EVAL_EXPR(18, ((int)((void*)10 + 10)) == 20 ? 1 : -1);
     37 
     38 struct s {
     39   int a[(int)-1.0f]; // expected-error {{'a' declared as an array with a negative size}}
     40 };
     41 
     42 EVAL_EXPR(19, ((int)&*(char*)10 == 10 ? 1 : -1));
     43 
     44 EVAL_EXPR(20, __builtin_constant_p(*((int*) 10)));
     45 
     46 EVAL_EXPR(21, (__imag__ 2i) == 2 ? 1 : -1);
     47 
     48 EVAL_EXPR(22, (__real__ (2i+3)) == 3 ? 1 : -1);
     49 
     50 int g23[(int)(1.0 / 1.0)] = { 1 };
     51 int g24[(int)(1.0 / 1.0)] = { 1 , 2 }; // expected-warning {{excess elements in array initializer}}
     52 int g25[(int)(1.0 + 1.0)], g26 = sizeof(g25);
     53 
     54 EVAL_EXPR(26, (_Complex double)0 ? -1 : 1)
     55 EVAL_EXPR(27, (_Complex int)0 ? -1 : 1)
     56 EVAL_EXPR(28, (_Complex double)1 ? 1 : -1)
     57 EVAL_EXPR(29, (_Complex int)1 ? 1 : -1)
     58 
     59 
     60 // PR4027 + rdar://6808859
     61 struct a { int x, y; };
     62 static struct a V2 = (struct a)(struct a){ 1, 2};
     63 static const struct a V1 = (struct a){ 1, 2};
     64 
     65 EVAL_EXPR(30, (int)(_Complex float)((1<<30)-1) == (1<<30) ? 1 : -1)
     66 EVAL_EXPR(31, (int*)0 == (int*)0 ? 1 : -1)
     67 EVAL_EXPR(32, (int*)0 != (int*)0 ? -1 : 1)
     68 EVAL_EXPR(33, (void*)0 - (void*)0 == 0 ? 1 : -1)
     69 void foo(void) {}
     70 EVAL_EXPR(34, (foo == (void *)0) ? -1 : 1)
     71 
     72 // No PR. Mismatched bitwidths lead to a crash on second evaluation.
     73 const _Bool constbool = 0;
     74 EVAL_EXPR(35, constbool)
     75 EVAL_EXPR(36, constbool)
     76 
     77 EVAL_EXPR(37, (1,2.0) == 2.0 ? 1 : -1)
     78 EVAL_EXPR(38, __builtin_expect(1,1) == 1 ? 1 : -1)
     79 
     80 // PR7884
     81 EVAL_EXPR(39, __real__(1.f) == 1 ? 1 : -1)
     82 EVAL_EXPR(40, __imag__(1.f) == 0 ? 1 : -1)
     83 
     84 // rdar://8875946
     85 void rdar8875946() {
     86   double _Complex  P;
     87   float _Complex  P2 = 3.3f + P;
     88 }
     89