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 | |
| 3 | int test1(int x) { |
Chris Lattner | e44e5cc | 2009-04-18 09:36:27 +0000 | [diff] [blame] | 4 | goto L; // expected-error{{illegal goto into protected scope}} |
Chris Lattner | 930cc9a | 2009-04-18 18:42:55 +0000 | [diff] [blame] | 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}} |
Eli Friedman | 9c0e6f9 | 2009-02-28 05:41:13 +0000 | [diff] [blame] | 7 | L: |
| 8 | return sizeof a; |
| 9 | } |
Eli Friedman | ea91729 | 2009-02-28 06:22:14 +0000 | [diff] [blame] | 10 | |
| 11 | int test2(int x) { |
Chris Lattner | e44e5cc | 2009-04-18 09:36:27 +0000 | [diff] [blame] | 12 | goto L; // expected-error{{illegal goto into protected scope}} |
Chris Lattner | 930cc9a | 2009-04-18 18:42:55 +0000 | [diff] [blame] | 13 | typedef int a[x]; // expected-note {{jump bypasses initialization of VLA typedef}} |
Eli Friedman | ea91729 | 2009-02-28 06:22:14 +0000 | [diff] [blame] | 14 | L: |
| 15 | return sizeof(a); |
| 16 | } |
| 17 | |
| 18 | void test3clean(int*); |
| 19 | |
| 20 | int test3() { |
Chris Lattner | e44e5cc | 2009-04-18 09:36:27 +0000 | [diff] [blame] | 21 | goto L; // expected-error{{illegal goto into protected scope}} |
Chris Lattner | 930cc9a | 2009-04-18 18:42:55 +0000 | [diff] [blame] | 22 | int a __attribute((cleanup(test3clean))); // expected-note {{jump bypasses initialization of declaration with __attribute__((cleanup))}} |
Chris Lattner | 01c5fc0 | 2009-04-18 07:54:11 +0000 | [diff] [blame] | 23 | L: |
Eli Friedman | ea91729 | 2009-02-28 06:22:14 +0000 | [diff] [blame] | 24 | return a; |
| 25 | } |
Steve Naroff | d91d1f8 | 2009-04-15 16:58:41 +0000 | [diff] [blame] | 26 | |
| 27 | int test4(int x) { |
Chris Lattner | e44e5cc | 2009-04-18 09:36:27 +0000 | [diff] [blame] | 28 | goto L; // expected-error{{illegal goto into protected scope}} |
Chris Lattner | 930cc9a | 2009-04-18 18:42:55 +0000 | [diff] [blame] | 29 | int a[x]; // expected-note {{jump bypasses initialization of variable length array}} |
Chris Lattner | 01c5fc0 | 2009-04-18 07:54:11 +0000 | [diff] [blame] | 30 | test4(x); |
| 31 | L: |
| 32 | return sizeof a; |
Steve Naroff | d91d1f8 | 2009-04-15 16:58:41 +0000 | [diff] [blame] | 33 | } |
Chris Lattner | 01c5fc0 | 2009-04-18 07:54:11 +0000 | [diff] [blame] | 34 | |
| 35 | int test5(int x) { |
| 36 | int a[x]; |
| 37 | test5(x); |
| 38 | goto L; // Ok. |
| 39 | L: |
| 40 | goto L; // Ok. |
| 41 | return sizeof a; |
| 42 | } |
| 43 | |
Chris Lattner | e44e5cc | 2009-04-18 09:36:27 +0000 | [diff] [blame] | 44 | int test6() { |
| 45 | // just plain invalid. |
| 46 | goto x; // expected-error {{use of undeclared label 'x'}} |
| 47 | } |
| 48 | |
Chris Lattner | 69a480e | 2009-04-18 19:42:37 +0000 | [diff] [blame] | 49 | void test7(int x) { |
Chris Lattner | 2c8f7ce | 2009-04-18 19:50:02 +0000 | [diff] [blame] | 50 | switch (x) { |
Chris Lattner | 69a480e | 2009-04-18 19:42:37 +0000 | [diff] [blame] | 51 | case 1: ; |
| 52 | int a[x]; // expected-note {{jump bypasses initialization of variable length array}} |
Chris Lattner | 2c8f7ce | 2009-04-18 19:50:02 +0000 | [diff] [blame] | 53 | case 2: // expected-error {{illegal switch case into protected scope}} |
Chris Lattner | 69a480e | 2009-04-18 19:42:37 +0000 | [diff] [blame] | 54 | a[1] = 2; |
| 55 | break; |
| 56 | } |
| 57 | } |
| 58 | |
Chris Lattner | bfff199 | 2009-04-18 22:42:18 +0000 | [diff] [blame] | 59 | int test8(int x) { |
Chris Lattner | 0d1c0e2 | 2009-04-18 22:56:52 +0000 | [diff] [blame^] | 60 | // For statement. |
Chris Lattner | bfff199 | 2009-04-18 22:42:18 +0000 | [diff] [blame] | 61 | goto L2; // expected-error {{illegal goto into protected scope}} |
Chris Lattner | bfff199 | 2009-04-18 22:42:18 +0000 | [diff] [blame] | 62 | for (int arr[x]; // expected-note {{jump bypasses initialization of variable length array}} |
Chris Lattner | 0d1c0e2 | 2009-04-18 22:56:52 +0000 | [diff] [blame^] | 63 | ; ++x) |
Chris Lattner | bfff199 | 2009-04-18 22:42:18 +0000 | [diff] [blame] | 64 | L2:; |
Chris Lattner | 0d1c0e2 | 2009-04-18 22:56:52 +0000 | [diff] [blame^] | 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; }); |
Chris Lattner | bfff199 | 2009-04-18 22:42:18 +0000 | [diff] [blame] | 70 | |
Chris Lattner | 0d1c0e2 | 2009-04-18 22:56:52 +0000 | [diff] [blame^] | 71 | // Statement expressions 2. |
| 72 | goto L1; // expected-error {{illegal goto into protected scope}} |
Chris Lattner | bfff199 | 2009-04-18 22:42:18 +0000 | [diff] [blame] | 73 | return x == ({ |
| 74 | int a[x]; // expected-note {{jump bypasses initialization of variable length array}} |
Chris Lattner | 0d1c0e2 | 2009-04-18 22:56:52 +0000 | [diff] [blame^] | 75 | L1: |
Chris Lattner | bfff199 | 2009-04-18 22:42:18 +0000 | [diff] [blame] | 76 | 42; }); |
| 77 | } |