llvm-project/clang/test/SemaObjC/scope-check.m

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

104 lines
2.5 KiB
Mathematica
Raw Normal View History

Reapply "[Parse] Use CapturedStmt for @finally on MSVC" This reapplies r334224 and adds explicit triples to some tests to fix them on Windows (where otherwise they would have run with the default windows-msvc triple, which I'm changing the behavior for). Original commit message: The body of a `@finally` needs to be executed on both exceptional and non-exceptional paths. On landingpad platforms, this is straightforward: the `@finally` body is emitted as a normal (non-exceptional) cleanup, and then a catch-all is emitted which branches to that cleanup (the cleanup has code to conditionally re-throw based on a flag which is set by the catch-all). Unfortunately, we can't use the same approach for MSVC exceptions, where the catch-all will be emitted as a catchpad. We can't just branch to the cleanup from within the catchpad, since we can only exit it via a catchret, at which point the exception is destroyed and we can't rethrow. We could potentially emit the finally body inside the catchpad and have the normal cleanup path somehow branch into it, but that would require some new IR construct that could branch into a catchpad. Instead, after discussing it with Reid Kleckner, we decided that frontend outlining was the best approach, similar to how SEH `__finally` works today. We decided to use CapturedStmt (which was also suggested by Reid) rather than CaptureFinder (which is what `__finally` uses) since the latter doesn't handle a lot of cases we care about, e.g. self accesses, property accesses, block captures, etc. Extending CaptureFinder to handle those additional cases proved unwieldy, whereas CapturedStmt already took care of all of those. In theory `__finally` could also be moved over to CapturedStmt, which would remove some existing limitations (e.g. the inability to capture this), although CaptureFinder would still be needed for SEH filters. The one case supported by `@finally` but not CapturedStmt (or CaptureFinder for that matter) is arbitrary control flow out of the `@finally`, e.g. having a return statement inside a `@finally`. We can add that support as a follow-up, but in practice we've found it to be used very rarely anyway. Differential Revision: https://reviews.llvm.org/D47564 llvm-svn: 334251
2018-06-08 08:30:00 +08:00
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10 -fsyntax-only -verify -fobjc-exceptions -Wno-objc-root-class %s
@class A, B, C;
void test1() {
goto L; // expected-error{{cannot jump}}
goto L2; // expected-error{{cannot jump}}
goto L3; // expected-error{{cannot jump}}
@try { // expected-note {{jump bypasses initialization of @try block}}
L: ;
} @catch (A *x) { // expected-note {{jump bypasses initialization of @catch block}}
L2: ;
} @catch (B *x) {
} @catch (C *c) {
} @finally {// expected-note {{jump bypasses initialization of @finally block}}
L3: ;
}
@try {
goto L4; // expected-error{{cannot jump}}
goto L5; // expected-error{{cannot jump}}
} @catch (C *c) { // expected-note {{jump bypasses initialization of @catch block}}
L5: ;
goto L6; // expected-error{{cannot jump}}
} @catch (B *c) { // expected-note {{jump bypasses initialization of @catch block}}
L6: ;
} @finally { // expected-note {{jump bypasses initialization of @finally block}}
L4: ;
}
@try { // expected-note 2 {{jump bypasses initialization of @try block}}
L7: ;
} @catch (C *c) {
goto L7; // expected-error{{cannot jump}}
} @finally {
goto L7; // expected-error{{cannot jump}}
}
goto L8; // expected-error{{cannot jump}}
@try {
} @catch (A *c) {
} @catch (B *c) {
} @catch (C *c) { // expected-note {{jump bypasses initialization of @catch block}}
L8: ;
}
// rdar://6810106
id X;
goto L9; // expected-error{{cannot jump}}
goto L10; // ok
@synchronized // expected-note {{jump bypasses initialization of @synchronized block}}
( ({ L10: ; X; })) {
L9:
;
}
}
void test2(int a) {
if (a) goto L0;
@try {} @finally {}
L0:
return;
}
// rdar://6803963
void test3() {
@try {
goto blargh;
blargh: ;
} @catch (...) {}
}
@interface Greeter
+ (void) hello;
@end
@implementation Greeter
+ (void) hello {
@try {
goto blargh; // expected-error {{cannot jump}}
} @catch (...) { // expected-note {{jump bypasses initialization of @catch block}}
blargh: ;
}
}
+ (void)meth2 {
int n; void *P;
goto L0; // expected-error {{cannot jump}}
typedef int A[n]; // expected-note {{jump bypasses initialization of VLA typedef}}
L0:
goto L1; // expected-error {{cannot jump}}
A b, c[10]; // expected-note 2 {{jump bypasses initialization of variable length array}}
L1:
goto L2; // expected-error {{cannot jump}}
A d[n]; // expected-note {{jump bypasses initialization of variable length array}}
L2:
return;
}
@end