Daniel Dunbar | ffd408a | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s |
Eli Friedman | 9c0e6f9 | 2009-02-28 05:41:13 +0000 | [diff] [blame] | 2 | |
Chris Lattner | e44e5cc | 2009-04-18 09:36:27 +0000 | [diff] [blame^] | 3 | /* |
| 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 Friedman | 9c0e6f9 | 2009-02-28 05:41:13 +0000 | [diff] [blame] | 14 | int test1(int x) { |
Chris Lattner | e44e5cc | 2009-04-18 09:36:27 +0000 | [diff] [blame^] | 15 | 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 Friedman | 9c0e6f9 | 2009-02-28 05:41:13 +0000 | [diff] [blame] | 18 | L: |
| 19 | return sizeof a; |
| 20 | } |
Eli Friedman | ea91729 | 2009-02-28 06:22:14 +0000 | [diff] [blame] | 21 | |
| 22 | int test2(int x) { |
Chris Lattner | e44e5cc | 2009-04-18 09:36:27 +0000 | [diff] [blame^] | 23 | goto L; // expected-error{{illegal goto into protected scope}} |
| 24 | typedef int a[x]; // expected-note {{scope created by VLA typedef}} |
Eli Friedman | ea91729 | 2009-02-28 06:22:14 +0000 | [diff] [blame] | 25 | L: |
| 26 | return sizeof(a); |
| 27 | } |
| 28 | |
| 29 | void test3clean(int*); |
| 30 | |
| 31 | int test3() { |
Chris Lattner | e44e5cc | 2009-04-18 09:36:27 +0000 | [diff] [blame^] | 32 | goto L; // expected-error{{illegal goto into protected scope}} |
| 33 | int a __attribute((cleanup(test3clean))); // expected-note {{scope created by declaration with __attribute__((cleanup))}} |
Chris Lattner | 01c5fc0 | 2009-04-18 07:54:11 +0000 | [diff] [blame] | 34 | L: |
Eli Friedman | ea91729 | 2009-02-28 06:22:14 +0000 | [diff] [blame] | 35 | return a; |
| 36 | } |
Steve Naroff | d91d1f8 | 2009-04-15 16:58:41 +0000 | [diff] [blame] | 37 | |
| 38 | int test4(int x) { |
Chris Lattner | e44e5cc | 2009-04-18 09:36:27 +0000 | [diff] [blame^] | 39 | goto L; // expected-error{{illegal goto into protected scope}} |
| 40 | int a[x]; // expected-note {{scope created by variable length array}} |
Chris Lattner | 01c5fc0 | 2009-04-18 07:54:11 +0000 | [diff] [blame] | 41 | test4(x); |
| 42 | L: |
| 43 | return sizeof a; |
Steve Naroff | d91d1f8 | 2009-04-15 16:58:41 +0000 | [diff] [blame] | 44 | } |
Chris Lattner | 01c5fc0 | 2009-04-18 07:54:11 +0000 | [diff] [blame] | 45 | |
| 46 | int test5(int x) { |
| 47 | int a[x]; |
| 48 | test5(x); |
| 49 | goto L; // Ok. |
| 50 | L: |
| 51 | goto L; // Ok. |
| 52 | return sizeof a; |
| 53 | } |
| 54 | |
Chris Lattner | e44e5cc | 2009-04-18 09:36:27 +0000 | [diff] [blame^] | 55 | int test6() { |
| 56 | // just plain invalid. |
| 57 | goto x; // expected-error {{use of undeclared label 'x'}} |
| 58 | } |
| 59 | |
Chris Lattner | 01c5fc0 | 2009-04-18 07:54:11 +0000 | [diff] [blame] | 60 | |
| 61 | // FIXME: Switch cases etc. |