1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux %s -Wno-tautological-pointer-compare
2f4a2713aSLionel Sambuc
3f4a2713aSLionel Sambuc #define EVAL_EXPR(testno, expr) int test##testno = sizeof(struct{char qq[expr];});
4f4a2713aSLionel Sambuc int x;
5f4a2713aSLionel Sambuc EVAL_EXPR(1, (_Bool)&x)
6f4a2713aSLionel Sambuc EVAL_EXPR(2, (int)(1.0+(double)4))
7f4a2713aSLionel Sambuc EVAL_EXPR(3, (int)(1.0+(float)4.0))
8f4a2713aSLionel Sambuc EVAL_EXPR(4, (_Bool)(1 ? (void*)&x : 0))
9f4a2713aSLionel Sambuc EVAL_EXPR(5, (_Bool)(int[]){0})
10f4a2713aSLionel Sambuc struct y {int x,y;};
11f4a2713aSLionel Sambuc EVAL_EXPR(6, (int)(1+(struct y*)0))
12f4a2713aSLionel Sambuc EVAL_EXPR(7, (int)&((struct y*)0)->y)
13f4a2713aSLionel Sambuc EVAL_EXPR(8, (_Bool)"asdf")
14f4a2713aSLionel Sambuc EVAL_EXPR(9, !!&x)
15f4a2713aSLionel Sambuc EVAL_EXPR(10, ((void)1, 12))
16f4a2713aSLionel Sambuc void g0(void);
17f4a2713aSLionel Sambuc EVAL_EXPR(11, (g0(), 12)) // expected-error {{must have a constant size}}
18f4a2713aSLionel Sambuc EVAL_EXPR(12, 1.0&&2.0)
19f4a2713aSLionel Sambuc EVAL_EXPR(13, x || 3.0) // expected-error {{must have a constant size}}
20f4a2713aSLionel Sambuc
21f4a2713aSLionel Sambuc unsigned int l_19 = 1;
22f4a2713aSLionel Sambuc EVAL_EXPR(14, (1 ^ l_19) && 1); // expected-error {{fields must have a constant size}}
23f4a2713aSLionel Sambuc
f()24f4a2713aSLionel Sambuc void f()
25f4a2713aSLionel Sambuc {
26f4a2713aSLionel Sambuc int a;
27f4a2713aSLionel Sambuc EVAL_EXPR(15, (_Bool)&a);
28f4a2713aSLionel Sambuc }
29f4a2713aSLionel Sambuc
30f4a2713aSLionel Sambuc // FIXME: Turn into EVAL_EXPR test once we have more folding.
31f4a2713aSLionel Sambuc _Complex float g16 = (1.0f + 1.0fi);
32f4a2713aSLionel Sambuc
33f4a2713aSLionel Sambuc // ?: in constant expressions.
34f4a2713aSLionel Sambuc int g17[(3?:1) - 2];
35f4a2713aSLionel Sambuc
36f4a2713aSLionel Sambuc EVAL_EXPR(18, ((int)((void*)10 + 10)) == 20 ? 1 : -1);
37f4a2713aSLionel Sambuc
38f4a2713aSLionel Sambuc struct s {
39f4a2713aSLionel Sambuc int a[(int)-1.0f]; // expected-error {{'a' declared as an array with a negative size}}
40f4a2713aSLionel Sambuc };
41f4a2713aSLionel Sambuc
42f4a2713aSLionel Sambuc EVAL_EXPR(19, ((int)&*(char*)10 == 10 ? 1 : -1));
43f4a2713aSLionel Sambuc
44f4a2713aSLionel Sambuc EVAL_EXPR(20, __builtin_constant_p(*((int*) 10)));
45f4a2713aSLionel Sambuc
46f4a2713aSLionel Sambuc EVAL_EXPR(21, (__imag__ 2i) == 2 ? 1 : -1);
47f4a2713aSLionel Sambuc
48f4a2713aSLionel Sambuc EVAL_EXPR(22, (__real__ (2i+3)) == 3 ? 1 : -1);
49f4a2713aSLionel Sambuc
50f4a2713aSLionel Sambuc int g23[(int)(1.0 / 1.0)] = { 1 };
51f4a2713aSLionel Sambuc int g24[(int)(1.0 / 1.0)] = { 1 , 2 }; // expected-warning {{excess elements in array initializer}}
52f4a2713aSLionel Sambuc int g25[(int)(1.0 + 1.0)], g26 = sizeof(g25);
53f4a2713aSLionel Sambuc
54f4a2713aSLionel Sambuc EVAL_EXPR(26, (_Complex double)0 ? -1 : 1)
55f4a2713aSLionel Sambuc EVAL_EXPR(27, (_Complex int)0 ? -1 : 1)
56f4a2713aSLionel Sambuc EVAL_EXPR(28, (_Complex double)1 ? 1 : -1)
57f4a2713aSLionel Sambuc EVAL_EXPR(29, (_Complex int)1 ? 1 : -1)
58f4a2713aSLionel Sambuc
59f4a2713aSLionel Sambuc
60f4a2713aSLionel Sambuc // PR4027 + rdar://6808859
61f4a2713aSLionel Sambuc struct a { int x, y; };
62f4a2713aSLionel Sambuc static struct a V2 = (struct a)(struct a){ 1, 2};
63f4a2713aSLionel Sambuc static const struct a V1 = (struct a){ 1, 2};
64f4a2713aSLionel Sambuc
65f4a2713aSLionel Sambuc EVAL_EXPR(30, (int)(_Complex float)((1<<30)-1) == (1<<30) ? 1 : -1)
66f4a2713aSLionel Sambuc EVAL_EXPR(31, (int*)0 == (int*)0 ? 1 : -1)
67f4a2713aSLionel Sambuc EVAL_EXPR(32, (int*)0 != (int*)0 ? -1 : 1)
68f4a2713aSLionel Sambuc EVAL_EXPR(33, (void*)0 - (void*)0 == 0 ? 1 : -1)
foo(void)69f4a2713aSLionel Sambuc void foo(void) {}
70f4a2713aSLionel Sambuc EVAL_EXPR(34, (foo == (void *)0) ? -1 : 1)
71f4a2713aSLionel Sambuc
72f4a2713aSLionel Sambuc // No PR. Mismatched bitwidths lead to a crash on second evaluation.
73f4a2713aSLionel Sambuc const _Bool constbool = 0;
74f4a2713aSLionel Sambuc EVAL_EXPR(35, constbool)
75f4a2713aSLionel Sambuc EVAL_EXPR(36, constbool)
76f4a2713aSLionel Sambuc
77f4a2713aSLionel Sambuc EVAL_EXPR(37, (1,2.0) == 2.0 ? 1 : -1)
78f4a2713aSLionel Sambuc EVAL_EXPR(38, __builtin_expect(1,1) == 1 ? 1 : -1)
79f4a2713aSLionel Sambuc
80f4a2713aSLionel Sambuc // PR7884
81f4a2713aSLionel Sambuc EVAL_EXPR(39, __real__(1.f) == 1 ? 1 : -1)
82f4a2713aSLionel Sambuc EVAL_EXPR(40, __imag__(1.f) == 0 ? 1 : -1)
83f4a2713aSLionel Sambuc
84f4a2713aSLionel Sambuc // From gcc testsuite
85f4a2713aSLionel Sambuc EVAL_EXPR(41, (int)(1+(_Complex unsigned)2))
86f4a2713aSLionel Sambuc
87f4a2713aSLionel Sambuc // rdar://8875946
rdar8875946()88f4a2713aSLionel Sambuc void rdar8875946() {
89f4a2713aSLionel Sambuc double _Complex P;
90f4a2713aSLionel Sambuc float _Complex P2 = 3.3f + P;
91f4a2713aSLionel Sambuc }
92f4a2713aSLionel Sambuc
93f4a2713aSLionel Sambuc double d = (d = 0.0); // expected-error {{not a compile-time constant}}
94f4a2713aSLionel Sambuc double d2 = ++d; // expected-error {{not a compile-time constant}}
95f4a2713aSLionel Sambuc
96f4a2713aSLionel Sambuc int n = 2;
97f4a2713aSLionel Sambuc int intLvalue[*(int*)((long)&n ?: 1)] = { 1, 2 }; // expected-error {{variable length array}}
98f4a2713aSLionel Sambuc
99f4a2713aSLionel Sambuc union u { int a; char b[4]; };
100f4a2713aSLionel Sambuc char c = ((union u)(123456)).b[0]; // expected-error {{not a compile-time constant}}
101f4a2713aSLionel Sambuc
102f4a2713aSLionel Sambuc extern const int weak_int __attribute__((weak));
103f4a2713aSLionel Sambuc const int weak_int = 42;
104f4a2713aSLionel Sambuc int weak_int_test = weak_int; // expected-error {{not a compile-time constant}}
105f4a2713aSLionel Sambuc
106f4a2713aSLionel Sambuc int literalVsNull1 = "foo" == 0;
107f4a2713aSLionel Sambuc int literalVsNull2 = 0 == "foo";
108f4a2713aSLionel Sambuc
109f4a2713aSLionel Sambuc // PR11385.
110f4a2713aSLionel Sambuc int castViaInt[*(int*)(unsigned long)"test"]; // expected-error {{variable length array}}
111f4a2713aSLionel Sambuc
112f4a2713aSLionel Sambuc // PR11391.
113f4a2713aSLionel Sambuc struct PR11391 { _Complex float f; } pr11391;
114f4a2713aSLionel Sambuc EVAL_EXPR(42, __builtin_constant_p(pr11391.f = 1))
115f4a2713aSLionel Sambuc
116f4a2713aSLionel Sambuc // PR12043
117f4a2713aSLionel Sambuc float varfloat;
118f4a2713aSLionel Sambuc const float constfloat = 0;
119f4a2713aSLionel Sambuc EVAL_EXPR(43, varfloat && constfloat) // expected-error {{must have a constant size}}
120f4a2713aSLionel Sambuc
121f4a2713aSLionel Sambuc // <rdar://problem/11205586>
122f4a2713aSLionel Sambuc // (Make sure we continue to reject this.)
123f4a2713aSLionel Sambuc EVAL_EXPR(44, "x"[0]); // expected-error {{variable length array}}
124f4a2713aSLionel Sambuc
125f4a2713aSLionel Sambuc // <rdar://problem/10962435>
126f4a2713aSLionel Sambuc EVAL_EXPR(45, ((char*)-1) + 1 == 0 ? 1 : -1)
127f4a2713aSLionel Sambuc EVAL_EXPR(46, ((char*)-1) + 1 < (char*) -1 ? 1 : -1)
128f4a2713aSLionel Sambuc EVAL_EXPR(47, &x < &x + 1 ? 1 : -1)
129f4a2713aSLionel Sambuc EVAL_EXPR(48, &x != &x - 1 ? 1 : -1)
130f4a2713aSLionel Sambuc EVAL_EXPR(49, &x < &x - 100 ? 1 : -1) // expected-error {{must have a constant size}}
131f4a2713aSLionel Sambuc
132f4a2713aSLionel Sambuc extern struct Test50S Test50;
133f4a2713aSLionel Sambuc EVAL_EXPR(50, &Test50 < (struct Test50S*)((unsigned)&Test50 + 10)) // expected-error {{must have a constant size}}
134f4a2713aSLionel Sambuc
135f4a2713aSLionel Sambuc // <rdar://problem/11874571>
136f4a2713aSLionel Sambuc EVAL_EXPR(51, 0 != (float)1e99)
137