blob: b52e7a06ffc2bb92f7d08ee3dbd0d30a800ff1a9 [file] [log] [blame]
Patrick Beardb2f68202012-04-06 18:12:22 +00001// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions -Wno-objc-root-class %s
Steve Naroff1fc51942009-04-14 20:53:38 +00002
3@class A, B, C;
4
Chris Lattnera5251fc2009-04-18 09:36:27 +00005void test1() {
Stephen Hines176edba2014-12-01 14:53:08 -08006 goto L; // expected-error{{cannot jump}}
7 goto L2; // expected-error{{cannot jump}}
8 goto L3; // expected-error{{cannot jump}}
Chris Lattner07e775d2009-04-18 21:28:52 +00009 @try { // expected-note {{jump bypasses initialization of @try block}}
Steve Naroff1fc51942009-04-14 20:53:38 +000010L: ;
Chris Lattner07e775d2009-04-18 21:28:52 +000011 } @catch (A *x) { // expected-note {{jump bypasses initialization of @catch block}}
Steve Naroff1fc51942009-04-14 20:53:38 +000012L2: ;
13 } @catch (B *x) {
14 } @catch (C *c) {
Chris Lattner07e775d2009-04-18 21:28:52 +000015 } @finally {// expected-note {{jump bypasses initialization of @finally block}}
Steve Naroff1fc51942009-04-14 20:53:38 +000016L3: ;
17 }
Chris Lattner07e775d2009-04-18 21:28:52 +000018
19 @try {
Stephen Hines176edba2014-12-01 14:53:08 -080020 goto L4; // expected-error{{cannot jump}}
21 goto L5; // expected-error{{cannot jump}}
Chris Lattner07e775d2009-04-18 21:28:52 +000022 } @catch (C *c) { // expected-note {{jump bypasses initialization of @catch block}}
23 L5: ;
Stephen Hines176edba2014-12-01 14:53:08 -080024 goto L6; // expected-error{{cannot jump}}
Chris Lattner07e775d2009-04-18 21:28:52 +000025 } @catch (B *c) { // expected-note {{jump bypasses initialization of @catch block}}
26 L6: ;
27 } @finally { // expected-note {{jump bypasses initialization of @finally block}}
28 L4: ;
29 }
30
31
32 @try { // expected-note 2 {{jump bypasses initialization of @try block}}
33 L7: ;
34 } @catch (C *c) {
Stephen Hines176edba2014-12-01 14:53:08 -080035 goto L7; // expected-error{{cannot jump}}
Chris Lattner07e775d2009-04-18 21:28:52 +000036 } @finally {
Stephen Hines176edba2014-12-01 14:53:08 -080037 goto L7; // expected-error{{cannot jump}}
Chris Lattner07e775d2009-04-18 21:28:52 +000038 }
39
Stephen Hines176edba2014-12-01 14:53:08 -080040 goto L8; // expected-error{{cannot jump}}
Chris Lattner07e775d2009-04-18 21:28:52 +000041 @try {
Chris Lattnerdabbad02009-04-18 22:35:34 +000042 } @catch (A *c) {
43 } @catch (B *c) {
Chris Lattner07e775d2009-04-18 21:28:52 +000044 } @catch (C *c) { // expected-note {{jump bypasses initialization of @catch block}}
45 L8: ;
46 }
Chris Lattner46c3c4b2009-04-21 06:01:00 +000047
48 // rdar://6810106
49 id X;
Stephen Hines176edba2014-12-01 14:53:08 -080050 goto L9; // expected-error{{cannot jump}}
Chris Lattner46c3c4b2009-04-21 06:01:00 +000051 goto L10; // ok
52 @synchronized // expected-note {{jump bypasses initialization of @synchronized block}}
53 ( ({ L10: ; X; })) {
54 L9:
55 ;
56 }
Steve Naroff1fc51942009-04-14 20:53:38 +000057}
Steve Naroffb25ddfb2009-04-15 14:38:36 +000058
Chris Lattnera5251fc2009-04-18 09:36:27 +000059void test2(int a) {
Steve Naroffb25ddfb2009-04-15 14:38:36 +000060 if (a) goto L0;
61 @try {} @finally {}
62 L0:
63 return;
64}
Chris Lattnera5251fc2009-04-18 09:36:27 +000065
66// rdar://6803963
67void test3() {
68 @try {
69 goto blargh;
70 blargh: ;
71 } @catch (...) {}
72}
Chris Lattner5223af82009-04-18 22:37:38 +000073
74@interface Greeter
75+ (void) hello;
76@end
77
78@implementation Greeter
79+ (void) hello {
80
81 @try {
Stephen Hines176edba2014-12-01 14:53:08 -080082 goto blargh; // expected-error {{cannot jump}}
Chris Lattner5223af82009-04-18 22:37:38 +000083 } @catch (...) { // expected-note {{jump bypasses initialization of @catch block}}
84 blargh: ;
85 }
86}
Chris Lattner4f9c06a2009-04-19 05:20:37 +000087
88+ (void)meth2 {
89 int n; void *P;
Stephen Hines176edba2014-12-01 14:53:08 -080090 goto L0; // expected-error {{cannot jump}}
Chris Lattner4f9c06a2009-04-19 05:20:37 +000091 typedef int A[n]; // expected-note {{jump bypasses initialization of VLA typedef}}
92 L0:
93
Stephen Hines176edba2014-12-01 14:53:08 -080094 goto L1; // expected-error {{cannot jump}}
Chris Lattner4f9c06a2009-04-19 05:20:37 +000095 A b, c[10]; // expected-note 2 {{jump bypasses initialization of variable length array}}
96 L1:
Stephen Hines176edba2014-12-01 14:53:08 -080097 goto L2; // expected-error {{cannot jump}}
Chris Lattner4f9c06a2009-04-19 05:20:37 +000098 A d[n]; // expected-note {{jump bypasses initialization of variable length array}}
99 L2:
100 return;
101}
102
Chris Lattner5223af82009-04-18 22:37:38 +0000103@end