blob: 98662be621bcabae47c6ea9dc272759725ced3bb [file] [log] [blame]
Chris Lattnera03954e2009-04-18 23:07:55 +00001// RUN: clang-cc -fsyntax-only -verify -std=gnu99 %s
Eli Friedman9c0e6f92009-02-28 05:41:13 +00002
3int test1(int x) {
Chris Lattnere44e5cc2009-04-18 09:36:27 +00004 goto L; // expected-error{{illegal goto into protected scope}}
Chris Lattner930cc9a2009-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 Friedman9c0e6f92009-02-28 05:41:13 +00007 L:
8 return sizeof a;
9}
Eli Friedmanea917292009-02-28 06:22:14 +000010
11int test2(int x) {
Chris Lattnere44e5cc2009-04-18 09:36:27 +000012 goto L; // expected-error{{illegal goto into protected scope}}
Chris Lattner930cc9a2009-04-18 18:42:55 +000013 typedef int a[x]; // expected-note {{jump bypasses initialization of VLA typedef}}
Eli Friedmanea917292009-02-28 06:22:14 +000014 L:
15 return sizeof(a);
16}
17
18void test3clean(int*);
19
20int test3() {
Chris Lattnere44e5cc2009-04-18 09:36:27 +000021 goto L; // expected-error{{illegal goto into protected scope}}
Chris Lattner930cc9a2009-04-18 18:42:55 +000022int a __attribute((cleanup(test3clean))); // expected-note {{jump bypasses initialization of declaration with __attribute__((cleanup))}}
Chris Lattner01c5fc02009-04-18 07:54:11 +000023L:
Eli Friedmanea917292009-02-28 06:22:14 +000024 return a;
25}
Steve Naroffd91d1f82009-04-15 16:58:41 +000026
27int test4(int x) {
Chris Lattnere44e5cc2009-04-18 09:36:27 +000028 goto L; // expected-error{{illegal goto into protected scope}}
Chris Lattner930cc9a2009-04-18 18:42:55 +000029int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
Chris Lattner01c5fc02009-04-18 07:54:11 +000030 test4(x);
31L:
32 return sizeof a;
Steve Naroffd91d1f82009-04-15 16:58:41 +000033}
Chris Lattner01c5fc02009-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 Lattnere44e5cc2009-04-18 09:36:27 +000044int test6() {
45 // just plain invalid.
46 goto x; // expected-error {{use of undeclared label 'x'}}
47}
48
Chris Lattner69a480e2009-04-18 19:42:37 +000049void test7(int x) {
Chris Lattner2c8f7ce2009-04-18 19:50:02 +000050 switch (x) {
Chris Lattner69a480e2009-04-18 19:42:37 +000051 case 1: ;
52 int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
Chris Lattner2c8f7ce2009-04-18 19:50:02 +000053 case 2: // expected-error {{illegal switch case into protected scope}}
Chris Lattner69a480e2009-04-18 19:42:37 +000054 a[1] = 2;
55 break;
56 }
57}
58
Chris Lattnerbfff1992009-04-18 22:42:18 +000059int test8(int x) {
Chris Lattner0d1c0e22009-04-18 22:56:52 +000060 // For statement.
Chris Lattnerbfff1992009-04-18 22:42:18 +000061 goto L2; // expected-error {{illegal goto into protected scope}}
Chris Lattnerbfff1992009-04-18 22:42:18 +000062 for (int arr[x]; // expected-note {{jump bypasses initialization of variable length array}}
Chris Lattner0d1c0e22009-04-18 22:56:52 +000063 ; ++x)
Chris Lattnera03954e2009-04-18 23:07:55 +000064 L2:;
Chris Lattner0d1c0e22009-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 Lattnerbfff1992009-04-18 22:42:18 +000070
Chris Lattnerd811b502009-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.
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
Chris Lattnera03954e2009-04-18 23:07:55 +000099 {
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
Chris Lattnerd811b502009-04-18 23:01:20 +0000116
Chris Lattner0d1c0e22009-04-18 22:56:52 +0000117 // Statement expressions 2.
118 goto L1; // expected-error {{illegal goto into protected scope}}
Chris Lattnerbfff1992009-04-18 22:42:18 +0000119 return x == ({
120 int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
Chris Lattner0d1c0e22009-04-18 22:56:52 +0000121 L1:
Chris Lattnerbfff1992009-04-18 22:42:18 +0000122 42; });
123}