From bc2b91a8f682023acb6543257f7c08f68ea964ae Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 23 Sep 2011 23:11:38 +0000 Subject: [PATCH] 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 --- lib/Sema/SemaExpr.cpp | 5 ++++- test/SemaObjC/bad-property-synthesis-crash.m | 23 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/SemaObjC/bad-property-synthesis-crash.m 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()) { 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 -- 2.40.0