]> granicus.if.org Git - clang/commitdiff
objc - fixes a crash when undefined typed property
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 23 Sep 2011 23:11:38 +0000 (23:11 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 23 Sep 2011 23:11:38 +0000 (23:11 +0000)
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
test/SemaObjC/bad-property-synthesis-crash.m [new file with mode: 0644]

index 4dd43c8857fb99f3e07cb2ccf3bd670985d17aa2..31eb19e1747824731251cb47c18c5432ce286130 100644 (file)
@@ -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 (file)
index 0000000..a594979
--- /dev/null
@@ -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