init.c revision 392cf91c7b3270a9b27baa3c5b21a836f3330d98
14ef8dd6e8736097bf9e3c387139c668565d89dcaChris Lattner// RUN: clang %s -verify -fsyntax-only
24ef8dd6e8736097bf9e3c387139c668565d89dcaChris Lattner
3392cf91c7b3270a9b27baa3c5b21a836f3330d98Sebastian Redl#include <stdint.h>
4392cf91c7b3270a9b27baa3c5b21a836f3330d98Sebastian Redl
54ef8dd6e8736097bf9e3c387139c668565d89dcaChris Lattnertypedef void (* fp)(void);
64ef8dd6e8736097bf9e3c387139c668565d89dcaChris Lattnervoid foo(void);
7f6c717c3dca839dcd189b4a6fa46c8fe7a8bec1dDouglas Gregor
8f6c717c3dca839dcd189b4a6fa46c8fe7a8bec1dDouglas Gregor// PR clang/3377
9f6c717c3dca839dcd189b4a6fa46c8fe7a8bec1dDouglas Gregorfp a[(short int)1] = { foo };
104ef8dd6e8736097bf9e3c387139c668565d89dcaChris Lattner
114cc627111453b75519d5130b57e06256da7b00e8Chris Lattnerint myArray[5] = {1, 2, 3, 4, 5};
124cc627111453b75519d5130b57e06256da7b00e8Chris Lattnerint *myPointer2 = myArray;
134cc627111453b75519d5130b57e06256da7b00e8Chris Lattnerint *myPointer = &(myArray[2]);
144cc627111453b75519d5130b57e06256da7b00e8Chris Lattner
15d411e04db18f7d07a889d51086861b23cbe05518Chris Lattner
16d411e04db18f7d07a889d51086861b23cbe05518Chris Lattnerextern int x;
17d411e04db18f7d07a889d51086861b23cbe05518Chris Lattnervoid *g = &x;
18d411e04db18f7d07a889d51086861b23cbe05518Chris Lattnerint *h = &x;
19d411e04db18f7d07a889d51086861b23cbe05518Chris Lattner
20a312ce2bdaaff62f21d560bad6cb0519f613d334Eli Friedmanint test() {
21a312ce2bdaaff62f21d560bad6cb0519f613d334Eli Friedmanint a[10];
229f4d86389f99c5d66664382add340a2ea19ad134Sebastian Redlint b[10] = a; // expected-error {{initialization with '{...}' expected}}
231f6f54be86a514d531ec231fd837858a43cfe72eChris Lattnerint +; // expected-error {{expected identifier or '('}} expected-error {{parse error}}
24a312ce2bdaaff62f21d560bad6cb0519f613d334Eli Friedman}
25be34ac67225fc4af6134c7f3507c777cceeec867Chris Lattner
26be34ac67225fc4af6134c7f3507c777cceeec867Chris Lattner
27be34ac67225fc4af6134c7f3507c777cceeec867Chris Lattner// PR2050
28be34ac67225fc4af6134c7f3507c777cceeec867Chris Lattnerstruct cdiff_cmd {
29be34ac67225fc4af6134c7f3507c777cceeec867Chris Lattner          const char *name;
30be34ac67225fc4af6134c7f3507c777cceeec867Chris Lattner          unsigned short argc;
31be34ac67225fc4af6134c7f3507c777cceeec867Chris Lattner          int (*handler)();
32be34ac67225fc4af6134c7f3507c777cceeec867Chris Lattner};
33be34ac67225fc4af6134c7f3507c777cceeec867Chris Lattnerint cdiff_cmd_open();
34be34ac67225fc4af6134c7f3507c777cceeec867Chris Lattnerstruct cdiff_cmd commands[] = {
35be34ac67225fc4af6134c7f3507c777cceeec867Chris Lattner        {"OPEN", 1, &cdiff_cmd_open }
36be34ac67225fc4af6134c7f3507c777cceeec867Chris Lattner};
37be34ac67225fc4af6134c7f3507c777cceeec867Chris Lattner
3897c0a391138d20e1066174a9cfa92860fb06e5a1Eli Friedman// PR2348
3997c0a391138d20e1066174a9cfa92860fb06e5a1Eli Friedmanstatic struct { int z; } s[2];
4097c0a391138d20e1066174a9cfa92860fb06e5a1Eli Friedmanint *t = &(*s).z;
4197c0a391138d20e1066174a9cfa92860fb06e5a1Eli Friedman
4297c0a391138d20e1066174a9cfa92860fb06e5a1Eli Friedman// PR2349
4397c0a391138d20e1066174a9cfa92860fb06e5a1Eli Friedmanshort *a2(void)
4497c0a391138d20e1066174a9cfa92860fb06e5a1Eli Friedman{
4597c0a391138d20e1066174a9cfa92860fb06e5a1Eli Friedman  short int b;
46d8803632d248a360a040ff03eff1162988058036Chris Lattner  static short *bp = &b; // expected-error {{initializer element is not a compile-time constant}}
4797c0a391138d20e1066174a9cfa92860fb06e5a1Eli Friedman
4897c0a391138d20e1066174a9cfa92860fb06e5a1Eli Friedman  return bp;
4997c0a391138d20e1066174a9cfa92860fb06e5a1Eli Friedman}
50f8f873deef78de611dd793a1e1201bef0d5a54a3Eli Friedman
51f8f873deef78de611dd793a1e1201bef0d5a54a3Eli Friedmanint pbool(void) {
52f8f873deef78de611dd793a1e1201bef0d5a54a3Eli Friedman  typedef const _Bool cbool;
53f8f873deef78de611dd793a1e1201bef0d5a54a3Eli Friedman  _Bool pbool1 = (void *) 0;
54f8f873deef78de611dd793a1e1201bef0d5a54a3Eli Friedman  cbool pbool2 = &pbool;
55f8f873deef78de611dd793a1e1201bef0d5a54a3Eli Friedman  return pbool2;
56f8f873deef78de611dd793a1e1201bef0d5a54a3Eli Friedman}
57f8f873deef78de611dd793a1e1201bef0d5a54a3Eli Friedman
58d5bac5704768606c3182dcc1386de12b3944601bChris Lattner
59d5bac5704768606c3182dcc1386de12b3944601bChris Lattner// rdar://5870981
60d5bac5704768606c3182dcc1386de12b3944601bChris Lattnerunion { float f; unsigned u; } u = { 1.0f };
61d5bac5704768606c3182dcc1386de12b3944601bChris Lattner
621e465df22f312a3661d70fc15b1a55dc97ebfce8Daniel Dunbar// rdar://6156694
631e465df22f312a3661d70fc15b1a55dc97ebfce8Daniel Dunbarint f3(int x) { return x; }
641e465df22f312a3661d70fc15b1a55dc97ebfce8Daniel Dunbartypedef void (*vfunc)(void);
651e465df22f312a3661d70fc15b1a55dc97ebfce8Daniel Dunbarvoid *bar = (vfunc) f3;
66b529d830b3b1667157da92ab0b5c32e1acfafbabEli Friedman
67b529d830b3b1667157da92ab0b5c32e1acfafbabEli Friedman// PR2747
68b529d830b3b1667157da92ab0b5c32e1acfafbabEli Friedmanstruct sym_reg {
69b529d830b3b1667157da92ab0b5c32e1acfafbabEli Friedman        char nc_gpreg;
70b529d830b3b1667157da92ab0b5c32e1acfafbabEli Friedman};
71b529d830b3b1667157da92ab0b5c32e1acfafbabEli Friedmanint sym_fw1a_scr[] = {
7267c8601677a6a4b01a77855b8b51240ef44acfb3Nuno Lopes           ((int)(&((struct sym_reg *)0)->nc_gpreg)) & 0,
7367c8601677a6a4b01a77855b8b51240ef44acfb3Nuno Lopes           8 * ((int)(&((struct sym_reg *)0)->nc_gpreg))
74b529d830b3b1667157da92ab0b5c32e1acfafbabEli Friedman};
75e2f56196e916e4d2f9eeec5c8978490cdedb3f64Chris Lattner
76e2f56196e916e4d2f9eeec5c8978490cdedb3f64Chris Lattner// PR3001
77e2f56196e916e4d2f9eeec5c8978490cdedb3f64Chris Lattnerstruct s1 s2 = {
784ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor    .a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}} \
794ec339f43c0cae2678334850c90926bea10999c7Douglas Gregor                            // expected-note{{forward declaration of 'struct s3'}}
80e2f56196e916e4d2f9eeec5c8978490cdedb3f64Chris Lattner    .b = bogus // expected-error {{use of undeclared identifier 'bogus'}}
81e2f56196e916e4d2f9eeec5c8978490cdedb3f64Chris Lattner}
82e2f56196e916e4d2f9eeec5c8978490cdedb3f64Chris Lattner
8391b9f2072a20906dd34ac6cb83813debf3595328Anders Carlsson// PR3382
8491b9f2072a20906dd34ac6cb83813debf3595328Anders Carlssonchar t[] = ("Hello");
85d079b2d6005bdade40ae4a0f228aba2affc591cfDouglas Gregor
86d079b2d6005bdade40ae4a0f228aba2affc591cfDouglas Gregor// <rdar://problem/6094855>
87d079b2d6005bdade40ae4a0f228aba2affc591cfDouglas Gregortypedef struct { } empty;
88d079b2d6005bdade40ae4a0f228aba2affc591cfDouglas Gregor
89d079b2d6005bdade40ae4a0f228aba2affc591cfDouglas Gregortypedef struct {
90d079b2d6005bdade40ae4a0f228aba2affc591cfDouglas Gregor  empty e;
91d079b2d6005bdade40ae4a0f228aba2affc591cfDouglas Gregor  int i2;
92d079b2d6005bdade40ae4a0f228aba2affc591cfDouglas Gregor} st;
93d079b2d6005bdade40ae4a0f228aba2affc591cfDouglas Gregor
94d079b2d6005bdade40ae4a0f228aba2affc591cfDouglas Gregorst st1 = { .i2 = 1 };
95d079b2d6005bdade40ae4a0f228aba2affc591cfDouglas Gregor
96d079b2d6005bdade40ae4a0f228aba2affc591cfDouglas Gregor// <rdar://problem/6096826>
97d079b2d6005bdade40ae4a0f228aba2affc591cfDouglas Gregorstruct {
98d079b2d6005bdade40ae4a0f228aba2affc591cfDouglas Gregor  int a;
99d079b2d6005bdade40ae4a0f228aba2affc591cfDouglas Gregor  int z[2];
100d079b2d6005bdade40ae4a0f228aba2affc591cfDouglas Gregor} y = { .z = {} };
101d863517ab7e936cbc3244a0fc431c8b672f5ece4Douglas Gregor
102d863517ab7e936cbc3244a0fc431c8b672f5ece4Douglas Gregorint bbb[10];
103d863517ab7e936cbc3244a0fc431c8b672f5ece4Douglas Gregor
104d863517ab7e936cbc3244a0fc431c8b672f5ece4Douglas Gregorstruct foo2 {
105d863517ab7e936cbc3244a0fc431c8b672f5ece4Douglas Gregor   unsigned a;
106d863517ab7e936cbc3244a0fc431c8b672f5ece4Douglas Gregor};
107d863517ab7e936cbc3244a0fc431c8b672f5ece4Douglas Gregor
108d863517ab7e936cbc3244a0fc431c8b672f5ece4Douglas Gregorstruct foo2 bar2[] = {
109392cf91c7b3270a9b27baa3c5b21a836f3330d98Sebastian Redl   { (intptr_t)bbb }
110d863517ab7e936cbc3244a0fc431c8b672f5ece4Douglas Gregor};
111