scope-check.c revision c78476b711902757f3600d75b180e8fe299c3f33
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  }
87
88  {
89  L7: ;// ok
90    int A[x], B = ({ if (x)
91                       goto L7;
92                     else
93                       goto L8;  // expected-error {{illegal goto into protected scope}}
94                     4; }),
95        C[x];   // expected-note {{jump bypasses initialization of variable length array}}
96  L8:; // bad
97  }
98
99  {
100  L9: ;// ok
101    int A[({ if (x)
102               goto L9;
103             else
104               // FIXME:
105               goto L10;  // fixme-error {{illegal goto into protected scope}}
106           4; })];
107  L10:; // bad
108  }
109
110  {
111    // FIXME: Crashes goto checker.
112    //goto L11;// ok
113    //int A[({   L11: 4; })];
114  }
115
116
117  // Statement expressions 2.
118  goto L1;     // expected-error {{illegal goto into protected scope}}
119  return x == ({
120                 int a[x];   // expected-note {{jump bypasses initialization of variable length array}}
121               L1:
122                 42; });
123}
124