blob: f8110079d0eb47fd44479d714fc83457c04eaaa3 [file] [log] [blame]
Daniel Dunbarc79f7672010-09-07 22:54:28 +00001// RUN: %clang_cc1 %s -verify -fsyntax-only -ffreestanding
Chris Lattner4ef8dd62007-11-01 02:45:17 +00002
Eli Friedmanbb6415c2009-05-31 10:54:53 +00003#include <stddef.h>
Sebastian Redl392cf912009-02-07 00:23:52 +00004#include <stdint.h>
5
Chris Lattner4ef8dd62007-11-01 02:45:17 +00006typedef void (* fp)(void);
7void foo(void);
Douglas Gregorf6c717c2009-01-23 16:54:12 +00008
9// PR clang/3377
10fp a[(short int)1] = { foo };
Chris Lattner4ef8dd62007-11-01 02:45:17 +000011
Chris Lattner4cc62712007-11-27 21:35:27 +000012int myArray[5] = {1, 2, 3, 4, 5};
13int *myPointer2 = myArray;
14int *myPointer = &(myArray[2]);
15
Chris Lattnerd411e042007-12-02 07:47:49 +000016
17extern int x;
18void *g = &x;
19int *h = &x;
20
Eli Friedmana312ce22008-02-08 00:48:24 +000021int test() {
22int a[10];
Eli Friedmancfdc81a2009-12-19 08:11:05 +000023int b[10] = a; // expected-error {{array initializer must be an initializer list}}
John McCalld8ac0572009-11-03 19:26:08 +000024int +; // expected-error {{expected identifier or '('}}
Eli Friedmana312ce22008-02-08 00:48:24 +000025}
Chris Lattnerbe34ac62008-05-04 01:13:36 +000026
27
28// PR2050
29struct cdiff_cmd {
30 const char *name;
31 unsigned short argc;
32 int (*handler)();
33};
34int cdiff_cmd_open();
35struct cdiff_cmd commands[] = {
36 {"OPEN", 1, &cdiff_cmd_open }
37};
38
Eli Friedman97c0a392008-05-21 03:39:11 +000039// PR2348
40static struct { int z; } s[2];
41int *t = &(*s).z;
42
43// PR2349
44short *a2(void)
45{
46 short int b;
Chris Lattnerd8803632008-08-10 01:58:45 +000047 static short *bp = &b; // expected-error {{initializer element is not a compile-time constant}}
Eli Friedman97c0a392008-05-21 03:39:11 +000048
49 return bp;
50}
Eli Friedmanf8f873d2008-05-30 18:07:22 +000051
52int pbool(void) {
53 typedef const _Bool cbool;
54 _Bool pbool1 = (void *) 0;
55 cbool pbool2 = &pbool;
56 return pbool2;
57}
58
Chris Lattnerd5bac572008-08-19 00:58:40 +000059
60// rdar://5870981
61union { float f; unsigned u; } u = { 1.0f };
62
Daniel Dunbar1e465df2008-08-25 20:08:27 +000063// rdar://6156694
64int f3(int x) { return x; }
65typedef void (*vfunc)(void);
66void *bar = (vfunc) f3;
Eli Friedmanb529d832008-09-02 09:37:00 +000067
68// PR2747
69struct sym_reg {
70 char nc_gpreg;
71};
72int sym_fw1a_scr[] = {
Nuno Lopes67c86012008-09-02 10:10:14 +000073 ((int)(&((struct sym_reg *)0)->nc_gpreg)) & 0,
74 8 * ((int)(&((struct sym_reg *)0)->nc_gpreg))
Eli Friedmanb529d832008-09-02 09:37:00 +000075};
Chris Lattnere2f56192008-11-03 09:28:22 +000076
77// PR3001
John McCall7727acf2010-03-31 02:13:20 +000078struct s1 s2 = { // expected-error {{variable has incomplete type 'struct s1'}} \
79 // expected-note {{forward declaration of 'struct s1'}}
Douglas Gregor4ec339f2009-01-19 19:26:10 +000080 .a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}} \
81 // expected-note{{forward declaration of 'struct s3'}}
Chris Lattnere2f56192008-11-03 09:28:22 +000082 .b = bogus // expected-error {{use of undeclared identifier 'bogus'}}
83}
84
Anders Carlsson91b9f202009-01-24 17:47:50 +000085// PR3382
86char t[] = ("Hello");
Douglas Gregord079b2d2009-01-30 17:42:28 +000087
88// <rdar://problem/6094855>
89typedef struct { } empty;
90
91typedef struct {
92 empty e;
93 int i2;
94} st;
95
96st st1 = { .i2 = 1 };
97
98// <rdar://problem/6096826>
99struct {
100 int a;
101 int z[2];
102} y = { .z = {} };
Douglas Gregord8635172009-02-02 21:35:47 +0000103
104int bbb[10];
105
106struct foo2 {
Eli Friedmanc91b7d92009-02-22 07:40:57 +0000107 uintptr_t a;
Douglas Gregord8635172009-02-02 21:35:47 +0000108};
109
110struct foo2 bar2[] = {
Sebastian Redl392cf912009-02-07 00:23:52 +0000111 { (intptr_t)bbb }
Douglas Gregord8635172009-02-02 21:35:47 +0000112};
Douglas Gregor7c53ca62009-02-18 22:23:55 +0000113
114struct foo2 bar3 = { 1, 2 }; // expected-warning{{excess elements in struct initializer}}
Eli Friedman91110ee2009-02-23 04:23:56 +0000115
116int* ptest1 = __builtin_choose_expr(1, (int*)0, (int*)0);
117
118typedef int32_t ivector4 __attribute((vector_size(16)));
119ivector4 vtest1 = 1 ? (ivector4){1} : (ivector4){1};
120ivector4 vtest2 = __builtin_choose_expr(1, (ivector4){1}, (ivector4){1});
Eli Friedman91110ee2009-02-23 04:23:56 +0000121
Eli Friedman42edd0d2009-03-24 01:14:50 +0000122uintptr_t ptrasintadd1 = (uintptr_t)&a - 4;
123uintptr_t ptrasintadd2 = (uintptr_t)&a + 4;
124uintptr_t ptrasintadd3 = 4 + (uintptr_t)&a;
Eli Friedmanbb6415c2009-05-31 10:54:53 +0000125
126// PR4285
127const wchar_t widestr[] = L"asdf";
Eli Friedman67f85fc2009-12-04 02:12:53 +0000128
129// PR5447
130const double pr5447 = (0.05 < -1.0) ? -1.0 : 0.0499878;
131
Rafael Espindolaa7d3c042010-05-07 15:18:43 +0000132// PR4386
133
134// None of these are constant initializers, but we implement GCC's old
135// behaviour of accepting bar and zed but not foo. GCC's behaviour was
136// changed in 2007 (rev 122551), so we should be able to change too one
137// day.
138int PR4386_bar();
139int PR4386_foo() __attribute((weak));
140int PR4386_zed();
141
142int PR4386_a = ((void *) PR4386_bar) != 0;
143int PR4386_b = ((void *) PR4386_foo) != 0; // expected-error{{initializer element is not a compile-time constant}}
144int PR4386_c = ((void *) PR4386_zed) != 0;
145int PR4386_zed() __attribute((weak));
Chris Lattner16c5dea2010-10-10 18:16:20 +0000146