init.c revision a5728872c7702ddd09537c95bc3cbd20e1f2fb09
1// RUN: %clang_cc1 %s -verify -fsyntax-only
2
3#include <stddef.h>
4#include <stdint.h>
5
6typedef void (* fp)(void);
7void foo(void);
8
9// PR clang/3377
10fp a[(short int)1] = { foo };
11
12int myArray[5] = {1, 2, 3, 4, 5};
13int *myPointer2 = myArray;
14int *myPointer = &(myArray[2]);
15
16
17extern int x;
18void *g = &x;
19int *h = &x;
20
21int test() {
22int a[10];
23int b[10] = a; // expected-error {{initialization with '{...}' expected}}
24int +; // expected-error {{expected identifier or '('}}
25}
26
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
39// PR2348
40static struct { int z; } s[2];
41int *t = &(*s).z;
42
43// PR2349
44short *a2(void)
45{
46  short int b;
47  static short *bp = &b; // expected-error {{initializer element is not a compile-time constant}}
48
49  return bp;
50}
51
52int pbool(void) {
53  typedef const _Bool cbool;
54  _Bool pbool1 = (void *) 0;
55  cbool pbool2 = &pbool;
56  return pbool2;
57}
58
59
60// rdar://5870981
61union { float f; unsigned u; } u = { 1.0f };
62
63// rdar://6156694
64int f3(int x) { return x; }
65typedef void (*vfunc)(void);
66void *bar = (vfunc) f3;
67
68// PR2747
69struct sym_reg {
70        char nc_gpreg;
71};
72int sym_fw1a_scr[] = {
73           ((int)(&((struct sym_reg *)0)->nc_gpreg)) & 0,
74           8 * ((int)(&((struct sym_reg *)0)->nc_gpreg))
75};
76
77// PR3001
78struct s1 s2 = {
79    .a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}} \
80                            // expected-note{{forward declaration of 'struct s3'}}
81    .b = bogus // expected-error {{use of undeclared identifier 'bogus'}}
82}
83
84// PR3382
85char t[] = ("Hello");
86
87// <rdar://problem/6094855>
88typedef struct { } empty;
89
90typedef struct {
91  empty e;
92  int i2;
93} st;
94
95st st1 = { .i2 = 1 };
96
97// <rdar://problem/6096826>
98struct {
99  int a;
100  int z[2];
101} y = { .z = {} };
102
103int bbb[10];
104
105struct foo2 {
106   uintptr_t a;
107};
108
109struct foo2 bar2[] = {
110   { (intptr_t)bbb }
111};
112
113struct foo2 bar3 = { 1, 2 }; // expected-warning{{excess elements in struct initializer}}
114
115int* ptest1 = __builtin_choose_expr(1, (int*)0, (int*)0);
116
117typedef int32_t ivector4 __attribute((vector_size(16)));
118ivector4 vtest1 = 1 ? (ivector4){1} : (ivector4){1};
119ivector4 vtest2 = __builtin_choose_expr(1, (ivector4){1}, (ivector4){1});
120ivector4 vtest3 = __real__ (ivector4){1};
121ivector4 vtest4 = __imag__ (ivector4){1};
122
123uintptr_t ptrasintadd1 = (uintptr_t)&a - 4;
124uintptr_t ptrasintadd2 = (uintptr_t)&a + 4;
125uintptr_t ptrasintadd3 = 4 + (uintptr_t)&a;
126
127// PR4285
128const wchar_t widestr[] = L"asdf";
129
130// PR5447
131const double pr5447 = (0.05 < -1.0) ? -1.0 : 0.0499878;
132
133