blob: 21908fc285d7ddb2c3fe1e835c90ffd2e8a14ad6 [file] [log] [blame]
Daniel Dunbarffd408a2009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only -verify %s
Eli Friedman9c0e6f92009-02-28 05:41:13 +00002
Chris Lattnere44e5cc2009-04-18 09:36:27 +00003/*
4"/tmp/bug.c", line 2: error: transfer of control bypasses initialization of:
5 variable length array "a" (declared at line 3)
6 variable length array "b" (declared at line 3)
7 goto L;
8 ^
9"/tmp/bug.c", line 3: warning: variable "b" was declared but never referenced
10 int a[x], b[x];
11 ^
12*/
13
Eli Friedman9c0e6f92009-02-28 05:41:13 +000014int test1(int x) {
Chris Lattnere44e5cc2009-04-18 09:36:27 +000015 goto L; // expected-error{{illegal goto into protected scope}}
16 int a[x]; // expected-note {{scope created by variable length array}}
17 int b[x]; // expected-note {{scope created by variable length array}}
Eli Friedman9c0e6f92009-02-28 05:41:13 +000018 L:
19 return sizeof a;
20}
Eli Friedmanea917292009-02-28 06:22:14 +000021
22int test2(int x) {
Chris Lattnere44e5cc2009-04-18 09:36:27 +000023 goto L; // expected-error{{illegal goto into protected scope}}
24 typedef int a[x]; // expected-note {{scope created by VLA typedef}}
Eli Friedmanea917292009-02-28 06:22:14 +000025 L:
26 return sizeof(a);
27}
28
29void test3clean(int*);
30
31int test3() {
Chris Lattnere44e5cc2009-04-18 09:36:27 +000032 goto L; // expected-error{{illegal goto into protected scope}}
33int a __attribute((cleanup(test3clean))); // expected-note {{scope created by declaration with __attribute__((cleanup))}}
Chris Lattner01c5fc02009-04-18 07:54:11 +000034L:
Eli Friedmanea917292009-02-28 06:22:14 +000035 return a;
36}
Steve Naroffd91d1f82009-04-15 16:58:41 +000037
38int test4(int x) {
Chris Lattnere44e5cc2009-04-18 09:36:27 +000039 goto L; // expected-error{{illegal goto into protected scope}}
40int a[x]; // expected-note {{scope created by variable length array}}
Chris Lattner01c5fc02009-04-18 07:54:11 +000041 test4(x);
42L:
43 return sizeof a;
Steve Naroffd91d1f82009-04-15 16:58:41 +000044}
Chris Lattner01c5fc02009-04-18 07:54:11 +000045
46int test5(int x) {
47 int a[x];
48 test5(x);
49 goto L; // Ok.
50L:
51 goto L; // Ok.
52 return sizeof a;
53}
54
Chris Lattnere44e5cc2009-04-18 09:36:27 +000055int test6() {
56 // just plain invalid.
57 goto x; // expected-error {{use of undeclared label 'x'}}
58}
59
Chris Lattner01c5fc02009-04-18 07:54:11 +000060
61// FIXME: Switch cases etc.