diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2011-09-23 23:11:38 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2011-09-23 23:11:38 +0000 |
commit | bc2b91a8f682023acb6543257f7c08f68ea964ae (patch) | |
tree | 27a58510f0918d90f710417bf411f4e841703925 | |
parent | 10904527359605a76561a49769a2199351a072d8 (diff) |
objc - fixes a crash when undefined typed property
followed by it implementation crashes when attempt
is made to access the synthesized ivar.
// rdar://10177744
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140432 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 5 | ||||
-rw-r--r-- | test/SemaObjC/bad-property-synthesis-crash.m | 23 |
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 4dd43c8857..31eb19e174 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1702,7 +1702,10 @@ ExprResult Sema::ActOnIdExpression(Scope *S, if (ObjCIvarDecl *Ivar = R.getAsSingle<ObjCIvarDecl>()) { R.clear(); ExprResult E(LookupInObjCMethod(R, S, Ivar->getIdentifier())); - assert(E.isInvalid() || E.get()); + // In a hopelessly buggy code, Objective-C instance variable + // lookup fails and no expression will be built to reference it. + if (!E.isInvalid() && !E.get()) + return ExprError(); return move(E); } } diff --git a/test/SemaObjC/bad-property-synthesis-crash.m b/test/SemaObjC/bad-property-synthesis-crash.m new file mode 100644 index 0000000000..a594979f14 --- /dev/null +++ b/test/SemaObjC/bad-property-synthesis-crash.m @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi -verify %s +// rdar://10177744 + +@interface Foo +@property (nonatomic, retain) NSString* what; // expected-error {{unknown type name 'NSString'}} \ + // expected-error {{property with}} \ + // expected-note {{previous definition is here}} +@end + +@implementation Foo +- (void) setWhat: (NSString*) value { // expected-error {{expected a type}} \ + // expected-warning {{conflicting parameter types in implementation of}} + __what; // expected-error {{use of undeclared identifier}} \ + // expected-warning {{expression result unused}} +} +@synthesize what; // expected-note 2 {{'what' declared here}} +@end + +@implementation Bar // expected-warning {{cannot find interface declaration for}} +- (NSString*) what { // expected-error {{expected a type}} + return __what; // expected-error {{use of undeclared identifier}} +} +@end |