blob: 4605e02b88062338810f20205c1cf535d6332ca1 [file] [log] [blame]
Chris Lattnerc78476b2009-04-18 23:07:55 +00001// RUN: clang-cc -fsyntax-only -verify -std=gnu99 %s
Eli Friedman8f17b662009-02-28 05:41:13 +00002
3int test1(int x) {
Chris Lattnera5251fc2009-04-18 09:36:27 +00004 goto L; // expected-error{{illegal goto into protected scope}}
Chris Lattner5ce71c92009-04-18 18:42:55 +00005 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}}
Eli Friedman8f17b662009-02-28 05:41:13 +00007 L:
8 return sizeof a;
9}
Eli Friedman709fa152009-02-28 06:22:14 +000010
11int test2(int x) {
Chris Lattnera5251fc2009-04-18 09:36:27 +000012 goto L; // expected-error{{illegal goto into protected scope}}
Chris Lattner5ce71c92009-04-18 18:42:55 +000013 typedef int a[x]; // expected-note {{jump bypasses initialization of VLA typedef}}
Eli Friedman709fa152009-02-28 06:22:14 +000014 L:
15 return sizeof(a);
16}
17
18void test3clean(int*);
19
20int test3() {
Chris Lattnera5251fc2009-04-18 09:36:27 +000021 goto L; // expected-error{{illegal goto into protected scope}}
Chris Lattner5ce71c92009-04-18 18:42:55 +000022int a __attribute((cleanup(test3clean))); // expected-note {{jump bypasses initialization of declaration with __attribute__((cleanup))}}
Chris Lattnerfd0c0cf2009-04-18 07:54:11 +000023L:
Eli Friedman709fa152009-02-28 06:22:14 +000024 return a;
25}
Steve Naroff1b6823d2009-04-15 16:58:41 +000026
27int test4(int x) {
Chris Lattnera5251fc2009-04-18 09:36:27 +000028 goto L; // expected-error{{illegal goto into protected scope}}
Chris Lattner5ce71c92009-04-18 18:42:55 +000029int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
Chris Lattnerfd0c0cf2009-04-18 07:54:11 +000030 test4(x);
31L:
32 return sizeof a;
Steve Naroff1b6823d2009-04-15 16:58:41 +000033}
Chris Lattnerfd0c0cf2009-04-18 07:54:11 +000034
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
Chris Lattnera5251fc2009-04-18 09:36:27 +000044int test6() {
45 // just plain invalid.
46 goto x; // expected-error {{use of undeclared label 'x'}}
47}
48
Chris Lattner366920a2009-04-18 19:42:37 +000049void test7(int x) {
Chris Lattnera9768b72009-04-18 19:50:02 +000050 switch (x) {
Chris Lattner366920a2009-04-18 19:42:37 +000051 case 1: ;
52 int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
Chris Lattnera9768b72009-04-18 19:50:02 +000053 case 2: // expected-error {{illegal switch case into protected scope}}
Chris Lattner366920a2009-04-18 19:42:37 +000054 a[1] = 2;
55 break;
56 }
57}
58
Chris Lattner35562d12009-04-18 22:42:18 +000059int test8(int x) {
Chris Lattner5b40e0c2009-04-18 22:56:52 +000060 // For statement.
Chris Lattner35562d12009-04-18 22:42:18 +000061 goto L2; // expected-error {{illegal goto into protected scope}}
Chris Lattner35562d12009-04-18 22:42:18 +000062 for (int arr[x]; // expected-note {{jump bypasses initialization of variable length array}}
Chris Lattner5b40e0c2009-04-18 22:56:52 +000063 ; ++x)
Chris Lattnerc78476b2009-04-18 23:07:55 +000064 L2:;
Chris Lattner5b40e0c2009-04-18 22:56:52 +000065
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; });
Chris Lattner35562d12009-04-18 22:42:18 +000070
Chris Lattner2b7b2ca2009-04-18 23:01:20 +000071 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.
Chris Lattner04ea2b62009-04-19 01:05:26 +000086 if (x) goto L6; // ok
Chris Lattner2b7b2ca2009-04-18 23:01:20 +000087 }
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
Chris Lattnerc78476b2009-04-18 23:07:55 +0000100 {
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
Chris Lattner04ea2b62009-04-19 01:05:26 +0000117 {
118 goto L12;
119
120 int y = 4; // fixme-warn: skips initializer.
121 L12:
122 ;
123 }
Chris Lattner2b7b2ca2009-04-18 23:01:20 +0000124
Chris Lattner5b40e0c2009-04-18 22:56:52 +0000125 // Statement expressions 2.
126 goto L1; // expected-error {{illegal goto into protected scope}}
Chris Lattner35562d12009-04-18 22:42:18 +0000127 return x == ({
128 int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
Chris Lattner5b40e0c2009-04-18 22:56:52 +0000129 L1:
Chris Lattner35562d12009-04-18 22:42:18 +0000130 42; });
131}
Chris Lattner04ea2b62009-04-19 01:05:26 +0000132
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