2010-09-08 06:54:28 +08:00
|
|
|
// RUN: %clang_cc1 %s -verify -fsyntax-only -ffreestanding
|
2007-11-01 10:45:17 +08:00
|
|
|
|
2009-05-31 18:54:53 +08:00
|
|
|
#include <stddef.h>
|
2009-02-07 08:23:52 +08:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2007-11-01 10:45:17 +08:00
|
|
|
typedef void (* fp)(void);
|
|
|
|
void foo(void);
|
2009-01-24 00:54:12 +08:00
|
|
|
|
|
|
|
// PR clang/3377
|
|
|
|
fp a[(short int)1] = { foo };
|
2007-11-01 10:45:17 +08:00
|
|
|
|
2007-11-28 05:35:27 +08:00
|
|
|
int myArray[5] = {1, 2, 3, 4, 5};
|
|
|
|
int *myPointer2 = myArray;
|
|
|
|
int *myPointer = &(myArray[2]);
|
|
|
|
|
2007-12-02 15:47:49 +08:00
|
|
|
|
|
|
|
extern int x;
|
|
|
|
void *g = &x;
|
|
|
|
int *h = &x;
|
|
|
|
|
2008-02-08 08:48:24 +08:00
|
|
|
int test() {
|
|
|
|
int a[10];
|
2009-12-19 16:11:05 +08:00
|
|
|
int b[10] = a; // expected-error {{array initializer must be an initializer list}}
|
2009-11-04 03:26:08 +08:00
|
|
|
int +; // expected-error {{expected identifier or '('}}
|
2008-02-08 08:48:24 +08:00
|
|
|
}
|
2008-05-04 09:13:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
// PR2050
|
|
|
|
struct cdiff_cmd {
|
|
|
|
const char *name;
|
|
|
|
unsigned short argc;
|
|
|
|
int (*handler)();
|
|
|
|
};
|
|
|
|
int cdiff_cmd_open();
|
|
|
|
struct cdiff_cmd commands[] = {
|
|
|
|
{"OPEN", 1, &cdiff_cmd_open }
|
|
|
|
};
|
|
|
|
|
2008-05-21 11:39:11 +08:00
|
|
|
// PR2348
|
|
|
|
static struct { int z; } s[2];
|
|
|
|
int *t = &(*s).z;
|
|
|
|
|
|
|
|
// PR2349
|
|
|
|
short *a2(void)
|
|
|
|
{
|
|
|
|
short int b;
|
2008-08-10 09:58:45 +08:00
|
|
|
static short *bp = &b; // expected-error {{initializer element is not a compile-time constant}}
|
2008-05-21 11:39:11 +08:00
|
|
|
|
|
|
|
return bp;
|
|
|
|
}
|
2008-05-31 02:07:22 +08:00
|
|
|
|
|
|
|
int pbool(void) {
|
|
|
|
typedef const _Bool cbool;
|
|
|
|
_Bool pbool1 = (void *) 0;
|
|
|
|
cbool pbool2 = &pbool;
|
|
|
|
return pbool2;
|
|
|
|
}
|
|
|
|
|
2008-08-19 08:58:40 +08:00
|
|
|
|
|
|
|
// rdar://5870981
|
|
|
|
union { float f; unsigned u; } u = { 1.0f };
|
|
|
|
|
2008-08-26 04:08:27 +08:00
|
|
|
// rdar://6156694
|
|
|
|
int f3(int x) { return x; }
|
|
|
|
typedef void (*vfunc)(void);
|
|
|
|
void *bar = (vfunc) f3;
|
2008-09-02 17:37:00 +08:00
|
|
|
|
|
|
|
// PR2747
|
|
|
|
struct sym_reg {
|
|
|
|
char nc_gpreg;
|
|
|
|
};
|
|
|
|
int sym_fw1a_scr[] = {
|
2008-09-02 18:10:14 +08:00
|
|
|
((int)(&((struct sym_reg *)0)->nc_gpreg)) & 0,
|
|
|
|
8 * ((int)(&((struct sym_reg *)0)->nc_gpreg))
|
2008-09-02 17:37:00 +08:00
|
|
|
};
|
2008-11-03 17:28:22 +08:00
|
|
|
|
|
|
|
// PR3001
|
2010-03-31 10:13:20 +08:00
|
|
|
struct s1 s2 = { // expected-error {{variable has incomplete type 'struct s1'}} \
|
|
|
|
// expected-note {{forward declaration of 'struct s1'}}
|
2009-01-20 03:26:10 +08:00
|
|
|
.a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}} \
|
|
|
|
// expected-note{{forward declaration of 'struct s3'}}
|
2008-11-03 17:28:22 +08:00
|
|
|
.b = bogus // expected-error {{use of undeclared identifier 'bogus'}}
|
|
|
|
}
|
|
|
|
|
2009-01-25 01:47:50 +08:00
|
|
|
// PR3382
|
|
|
|
char t[] = ("Hello");
|
2009-01-31 01:42:28 +08:00
|
|
|
|
|
|
|
// <rdar://problem/6094855>
|
|
|
|
typedef struct { } empty;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
empty e;
|
|
|
|
int i2;
|
|
|
|
} st;
|
|
|
|
|
|
|
|
st st1 = { .i2 = 1 };
|
|
|
|
|
|
|
|
// <rdar://problem/6096826>
|
|
|
|
struct {
|
|
|
|
int a;
|
|
|
|
int z[2];
|
|
|
|
} y = { .z = {} };
|
2009-02-03 05:35:47 +08:00
|
|
|
|
|
|
|
int bbb[10];
|
|
|
|
|
|
|
|
struct foo2 {
|
2009-02-22 15:40:57 +08:00
|
|
|
uintptr_t a;
|
2009-02-03 05:35:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct foo2 bar2[] = {
|
2009-02-07 08:23:52 +08:00
|
|
|
{ (intptr_t)bbb }
|
2009-02-03 05:35:47 +08:00
|
|
|
};
|
2009-02-19 06:23:55 +08:00
|
|
|
|
|
|
|
struct foo2 bar3 = { 1, 2 }; // expected-warning{{excess elements in struct initializer}}
|
2009-02-23 12:23:56 +08:00
|
|
|
|
|
|
|
int* ptest1 = __builtin_choose_expr(1, (int*)0, (int*)0);
|
|
|
|
|
|
|
|
typedef int32_t ivector4 __attribute((vector_size(16)));
|
|
|
|
ivector4 vtest1 = 1 ? (ivector4){1} : (ivector4){1};
|
|
|
|
ivector4 vtest2 = __builtin_choose_expr(1, (ivector4){1}, (ivector4){1});
|
|
|
|
|
2009-03-24 09:14:50 +08:00
|
|
|
uintptr_t ptrasintadd1 = (uintptr_t)&a - 4;
|
|
|
|
uintptr_t ptrasintadd2 = (uintptr_t)&a + 4;
|
|
|
|
uintptr_t ptrasintadd3 = 4 + (uintptr_t)&a;
|
2009-05-31 18:54:53 +08:00
|
|
|
|
|
|
|
// PR4285
|
|
|
|
const wchar_t widestr[] = L"asdf";
|
2009-12-04 10:12:53 +08:00
|
|
|
|
|
|
|
// PR5447
|
|
|
|
const double pr5447 = (0.05 < -1.0) ? -1.0 : 0.0499878;
|
|
|
|
|
2010-05-07 23:18:43 +08:00
|
|
|
// PR4386
|
|
|
|
|
|
|
|
// None of these are constant initializers, but we implement GCC's old
|
|
|
|
// behaviour of accepting bar and zed but not foo. GCC's behaviour was
|
|
|
|
// changed in 2007 (rev 122551), so we should be able to change too one
|
|
|
|
// day.
|
|
|
|
int PR4386_bar();
|
|
|
|
int PR4386_foo() __attribute((weak));
|
|
|
|
int PR4386_zed();
|
|
|
|
|
|
|
|
int PR4386_a = ((void *) PR4386_bar) != 0;
|
|
|
|
int PR4386_b = ((void *) PR4386_foo) != 0; // expected-error{{initializer element is not a compile-time constant}}
|
|
|
|
int PR4386_c = ((void *) PR4386_zed) != 0;
|
|
|
|
int PR4386_zed() __attribute((weak));
|
2010-10-11 02:16:20 +08:00
|
|
|
|