scope-check.c revision 04ea2b633a1f8ee662b8a99d2903a11c1b68e1ed
1// RUN: clang-cc -fsyntax-only -verify -std=gnu99 %s
2
3int test1(int x) {
4  goto L;    // expected-error{{illegal goto into protected scope}}
5  int a[x];  // expected-note {{jump bypasses initialization of variable length array}}
6  int b[x];  // expected-note {{jump bypasses initialization of variable length array}}
7  L:
8  return sizeof a;
9}
10
11int test2(int x) {
12  goto L;            // expected-error{{illegal goto into protected scope}}
13  typedef int a[x];  // expected-note {{jump bypasses initialization of VLA typedef}}
14  L:
15  return sizeof(a);
16}
17
18void test3clean(int*);
19
20int test3() {
21  goto L;            // expected-error{{illegal goto into protected scope}}
22int a __attribute((cleanup(test3clean))); // expected-note {{jump bypasses initialization of declaration with __attribute__((cleanup))}}
23L:
24  return a;
25}
26
27int test4(int x) {
28  goto L;       // expected-error{{illegal goto into protected scope}}
29int a[x];       // expected-note {{jump bypasses initialization of variable length array}}
30  test4(x);
31L:
32  return sizeof a;
33}
34
35int test5(int x) {
36  int a[x];
37  test5(x);
38  goto L;  // Ok.
39L:
40  goto L;  // Ok.
41  return sizeof a;
42}
43
44int test6() {
45  // just plain invalid.
46  goto x;  // expected-error {{use of undeclared label 'x'}}
47}
48
49void test7(int x) {
50  switch (x) {
51  case 1: ;
52    int a[x];       // expected-note {{jump bypasses initialization of variable length array}}
53  case 2:           // expected-error {{illegal switch case into protected scope}}
54    a[1] = 2;
55    break;
56  }
57}
58
59int test8(int x) {
60  // For statement.
61  goto L2;     // expected-error {{illegal goto into protected scope}}
62  for (int arr[x];   // expected-note {{jump bypasses initialization of variable length array}}
63       ; ++x)
64    L2:;
65
66  // Statement expressions.
67  goto L3;   // expected-error {{illegal goto into protected scope}}
68  int Y = ({  int a[x];   // expected-note {{jump bypasses initialization of variable length array}}
69           L3: 4; });
70
71  goto L4; // expected-error {{illegal goto into protected scope}}
72  {
73    int A[x],  // expected-note {{jump bypasses initialization of variable length array}}
74        B[x];  // expected-note {{jump bypasses initialization of variable length array}}
75  L4: ;
76  }
77
78  {
79  L5: ;// ok
80    int A[x], B = ({ if (x)
81                       goto L5;
82                     else
83                       goto L6;
84                   4; });
85  L6:; // ok.
86    if (x) goto L6; // ok
87  }
88
89  {
90  L7: ;// ok
91    int A[x], B = ({ if (x)
92                       goto L7;
93                     else
94                       goto L8;  // expected-error {{illegal goto into protected scope}}
95                     4; }),
96        C[x];   // expected-note {{jump bypasses initialization of variable length array}}
97  L8:; // bad
98  }
99
100  {
101  L9: ;// ok
102    int A[({ if (x)
103               goto L9;
104             else
105               // FIXME:
106               goto L10;  // fixme-error {{illegal goto into protected scope}}
107           4; })];
108  L10:; // bad
109  }
110
111  {
112    // FIXME: Crashes goto checker.
113    //goto L11;// ok
114    //int A[({   L11: 4; })];
115  }
116
117  {
118    goto L12;
119
120    int y = 4;   // fixme-warn: skips initializer.
121  L12:
122    ;
123  }
124
125  // Statement expressions 2.
126  goto L1;     // expected-error {{illegal goto into protected scope}}
127  return x == ({
128                 int a[x];   // expected-note {{jump bypasses initialization of variable length array}}
129               L1:
130                 42; });
131}
132
133void test9(int n, void *P) {
134  int Y;
135  int Z = 4;
136  goto *P;  // ok.
137
138L2: ;
139  int a[n];  // expected-note {{jump bypasses initialization of variable length array}}
140
141L3:
142  goto *P;  // expected-error {{illegal indirect goto in protected scope, unknown effect on scopes}}
143
144  void *Ptrs[] = {
145    &&L2,
146    &&L3   // FIXME: Not Ok.
147  };
148}
149
150