2011-11-16 15:18:12 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux %s
|
2008-11-12 17:44:48 +08:00
|
|
|
|
|
|
|
#define EVAL_EXPR(testno, expr) int test##testno = sizeof(struct{char qq[expr];});
|
|
|
|
int x;
|
|
|
|
EVAL_EXPR(1, (_Bool)&x)
|
|
|
|
EVAL_EXPR(2, (int)(1.0+(double)4))
|
|
|
|
EVAL_EXPR(3, (int)(1.0+(float)4.0))
|
|
|
|
EVAL_EXPR(4, (_Bool)(1 ? (void*)&x : 0))
|
|
|
|
EVAL_EXPR(5, (_Bool)(int[]){0})
|
|
|
|
struct y {int x,y;};
|
|
|
|
EVAL_EXPR(6, (int)(1+(struct y*)0))
|
|
|
|
EVAL_EXPR(7, (int)&((struct y*)0)->y)
|
|
|
|
EVAL_EXPR(8, (_Bool)"asdf")
|
2008-11-13 14:09:17 +08:00
|
|
|
EVAL_EXPR(9, !!&x)
|
|
|
|
EVAL_EXPR(10, ((void)1, 12))
|
|
|
|
void g0(void);
|
2011-12-07 08:43:50 +08:00
|
|
|
EVAL_EXPR(11, (g0(), 12)) // expected-error {{must have a constant size}}
|
2008-11-13 14:09:17 +08:00
|
|
|
EVAL_EXPR(12, 1.0&&2.0)
|
2011-12-07 08:43:50 +08:00
|
|
|
EVAL_EXPR(13, x || 3.0) // expected-error {{must have a constant size}}
|
2008-11-24 12:21:33 +08:00
|
|
|
|
|
|
|
unsigned int l_19 = 1;
|
|
|
|
EVAL_EXPR(14, (1 ^ l_19) && 1); // expected-error {{fields must have a constant size}}
|
2008-11-24 12:41:22 +08:00
|
|
|
|
|
|
|
void f()
|
|
|
|
{
|
|
|
|
int a;
|
2012-01-26 12:47:34 +08:00
|
|
|
EVAL_EXPR(15, (_Bool)&a);
|
2008-11-24 12:41:22 +08:00
|
|
|
}
|
2009-01-25 03:08:01 +08:00
|
|
|
|
|
|
|
// FIXME: Turn into EVAL_EXPR test once we have more folding.
|
|
|
|
_Complex float g16 = (1.0f + 1.0fi);
|
2009-02-18 08:47:45 +08:00
|
|
|
|
|
|
|
// ?: in constant expressions.
|
|
|
|
int g17[(3?:1) - 2];
|
2009-02-19 12:55:58 +08:00
|
|
|
|
2009-02-19 14:19:15 +08:00
|
|
|
EVAL_EXPR(18, ((int)((void*)10 + 10)) == 20 ? 1 : -1);
|
2009-02-19 14:30:50 +08:00
|
|
|
|
|
|
|
struct s {
|
2011-06-14 14:38:10 +08:00
|
|
|
int a[(int)-1.0f]; // expected-error {{'a' declared as an array with a negative size}}
|
2009-02-19 14:30:50 +08:00
|
|
|
};
|
2009-02-20 09:57:15 +08:00
|
|
|
|
|
|
|
EVAL_EXPR(19, ((int)&*(char*)10 == 10 ? 1 : -1));
|
2009-02-22 02:14:20 +08:00
|
|
|
|
2010-10-13 01:47:42 +08:00
|
|
|
EVAL_EXPR(20, __builtin_constant_p(*((int*) 10)));
|
2009-02-28 11:59:05 +08:00
|
|
|
|
|
|
|
EVAL_EXPR(21, (__imag__ 2i) == 2 ? 1 : -1);
|
|
|
|
|
|
|
|
EVAL_EXPR(22, (__real__ (2i+3)) == 3 ? 1 : -1);
|
|
|
|
|
2009-03-01 05:56:50 +08:00
|
|
|
int g23[(int)(1.0 / 1.0)] = { 1 };
|
|
|
|
int g24[(int)(1.0 / 1.0)] = { 1 , 2 }; // expected-warning {{excess elements in array initializer}}
|
|
|
|
int g25[(int)(1.0 + 1.0)], g26 = sizeof(g25);
|
2009-03-23 12:38:34 +08:00
|
|
|
|
|
|
|
EVAL_EXPR(26, (_Complex double)0 ? -1 : 1)
|
|
|
|
EVAL_EXPR(27, (_Complex int)0 ? -1 : 1)
|
|
|
|
EVAL_EXPR(28, (_Complex double)1 ? 1 : -1)
|
|
|
|
EVAL_EXPR(29, (_Complex int)1 ? 1 : -1)
|
2009-04-21 13:19:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
// PR4027 + rdar://6808859
|
2011-03-08 06:57:45 +08:00
|
|
|
struct a { int x, y; };
|
2009-04-21 13:19:11 +08:00
|
|
|
static struct a V2 = (struct a)(struct a){ 1, 2};
|
|
|
|
static const struct a V1 = (struct a){ 1, 2};
|
2009-04-23 03:23:09 +08:00
|
|
|
|
|
|
|
EVAL_EXPR(30, (int)(_Complex float)((1<<30)-1) == (1<<30) ? 1 : -1)
|
2009-04-29 03:17:36 +08:00
|
|
|
EVAL_EXPR(31, (int*)0 == (int*)0 ? 1 : -1)
|
|
|
|
EVAL_EXPR(32, (int*)0 != (int*)0 ? -1 : 1)
|
2009-06-05 04:04:03 +08:00
|
|
|
EVAL_EXPR(33, (void*)0 - (void*)0 == 0 ? 1 : -1)
|
2009-06-14 10:17:33 +08:00
|
|
|
void foo(void) {}
|
|
|
|
EVAL_EXPR(34, (foo == (void *)0) ? -1 : 1)
|
2009-11-06 05:10:57 +08:00
|
|
|
|
|
|
|
// No PR. Mismatched bitwidths lead to a crash on second evaluation.
|
|
|
|
const _Bool constbool = 0;
|
|
|
|
EVAL_EXPR(35, constbool)
|
|
|
|
EVAL_EXPR(36, constbool)
|
2009-11-16 12:25:37 +08:00
|
|
|
|
2010-08-15 04:52:13 +08:00
|
|
|
EVAL_EXPR(37, (1,2.0) == 2.0 ? 1 : -1)
|
|
|
|
EVAL_EXPR(38, __builtin_expect(1,1) == 1 ? 1 : -1)
|
|
|
|
|
|
|
|
// PR7884
|
|
|
|
EVAL_EXPR(39, __real__(1.f) == 1 ? 1 : -1)
|
|
|
|
EVAL_EXPR(40, __imag__(1.f) == 0 ? 1 : -1)
|
2011-01-19 02:49:33 +08:00
|
|
|
|
2011-11-12 11:56:23 +08:00
|
|
|
// From gcc testsuite
|
|
|
|
EVAL_EXPR(41, (int)(1+(_Complex unsigned)2))
|
|
|
|
|
2011-01-19 02:49:33 +08:00
|
|
|
// rdar://8875946
|
|
|
|
void rdar8875946() {
|
|
|
|
double _Complex P;
|
|
|
|
float _Complex P2 = 3.3f + P;
|
|
|
|
}
|
2011-10-29 07:26:52 +08:00
|
|
|
|
|
|
|
double d = (d = 0.0); // expected-error {{not a compile-time constant}}
|
2011-10-31 07:17:09 +08:00
|
|
|
double d2 = ++d; // expected-error {{not a compile-time constant}}
|
2011-10-30 06:55:55 +08:00
|
|
|
|
|
|
|
int n = 2;
|
|
|
|
int intLvalue[*(int*)((long)&n ?: 1)] = { 1, 2 }; // expected-error {{variable length array}}
|
2011-11-01 04:57:44 +08:00
|
|
|
|
|
|
|
union u { int a; char b[4]; };
|
|
|
|
char c = ((union u)(123456)).b[0]; // expected-error {{not a compile-time constant}}
|
2011-11-02 05:06:14 +08:00
|
|
|
|
|
|
|
extern const int weak_int __attribute__((weak));
|
|
|
|
const int weak_int = 42;
|
|
|
|
int weak_int_test = weak_int; // expected-error {{not a compile-time constant}}
|
2011-11-04 09:10:57 +08:00
|
|
|
|
|
|
|
int literalVsNull1 = "foo" == 0;
|
|
|
|
int literalVsNull2 = 0 == "foo";
|
2011-11-16 15:18:12 +08:00
|
|
|
|
|
|
|
// PR11385.
|
|
|
|
int castViaInt[*(int*)(unsigned long)"test"]; // expected-error {{variable length array}}
|
2011-11-17 01:22:48 +08:00
|
|
|
|
|
|
|
// PR11391.
|
|
|
|
struct PR11391 { _Complex float f; } pr11391;
|
|
|
|
EVAL_EXPR(42, __builtin_constant_p(pr11391.f = 1))
|
2012-02-22 06:41:33 +08:00
|
|
|
|
|
|
|
// PR12043
|
|
|
|
float varfloat;
|
|
|
|
const float constfloat = 0;
|
|
|
|
EVAL_EXPR(43, varfloat && constfloat) // expected-error {{must have a constant size}}
|
2012-04-12 07:32:29 +08:00
|
|
|
|
|
|
|
// <rdar://problem/11205586>
|
|
|
|
// (Make sure we continue to reject this.)
|
|
|
|
EVAL_EXPR(44, "x"[0]); // expected-error {{variable length array}}
|