scope-check.c revision 35562d18ea134f88ec09f12626f403a28adb4306
1// RUN: clang-cc -fsyntax-only -verify %s 2 3int test1(int x) { 4 goto L; // expected-error{{illegal goto into protected scope}} 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}} 7 L: 8 return sizeof a; 9} 10 11int test2(int x) { 12 goto L; // expected-error{{illegal goto into protected scope}} 13 typedef int a[x]; // expected-note {{jump bypasses initialization of VLA typedef}} 14 L: 15 return sizeof(a); 16} 17 18void test3clean(int*); 19 20int test3() { 21 goto L; // expected-error{{illegal goto into protected scope}} 22int a __attribute((cleanup(test3clean))); // expected-note {{jump bypasses initialization of declaration with __attribute__((cleanup))}} 23L: 24 return a; 25} 26 27int test4(int x) { 28 goto L; // expected-error{{illegal goto into protected scope}} 29int a[x]; // expected-note {{jump bypasses initialization of variable length array}} 30 test4(x); 31L: 32 return sizeof a; 33} 34 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 44int test6() { 45 // just plain invalid. 46 goto x; // expected-error {{use of undeclared label 'x'}} 47} 48 49void test7(int x) { 50 switch (x) { 51 case 1: ; 52 int a[x]; // expected-note {{jump bypasses initialization of variable length array}} 53 case 2: // expected-error {{illegal switch case into protected scope}} 54 a[1] = 2; 55 break; 56 } 57} 58 59int test8(int x) { 60 if (x) goto L; // expected-error {{illegal goto into protected scope}} 61 goto L2; // expected-error {{illegal goto into protected scope}} 62 63 for (int arr[x]; // expected-note {{jump bypasses initialization of variable length array}} 64 ; ++x) { 65 66 L2:; 67 } 68 69 return x == ({ 70 int a[x]; // expected-note {{jump bypasses initialization of variable length array}} 71 L: 72 42; }); 73} 74