[cfe-commits] r140432 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaObjC/bad-property-synthesis-crash.m

Fariborz Jahanian fjahanian at apple.com
Fri Sep 23 16:11:38 PDT 2011


Author: fjahanian
Date: Fri Sep 23 18:11:38 2011
New Revision: 140432

URL: http://llvm.org/viewvc/llvm-project?rev=140432&view=rev
Log:
objc - fixes a crash when undefined typed property
followed by it implementation crashes when attempt
is made to access the synthesized ivar. 
// rdar://10177744

Added:
    cfe/trunk/test/SemaObjC/bad-property-synthesis-crash.m
Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=140432&r1=140431&r2=140432&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Sep 23 18:11:38 2011
@@ -1702,7 +1702,10 @@
       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);
       }
     }

Added: cfe/trunk/test/SemaObjC/bad-property-synthesis-crash.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/bad-property-synthesis-crash.m?rev=140432&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/bad-property-synthesis-crash.m (added)
+++ cfe/trunk/test/SemaObjC/bad-property-synthesis-crash.m Fri Sep 23 18:11:38 2011
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1  -fsyntax-only -fobjc-nonfragile-abi -verify %s
+// rdar://10177744
+
+ at interface Foo
+ at property (nonatomic, retain) NSString* what; // expected-error {{unknown type name 'NSString'}} \
+                                              // expected-error {{property with}} \
+                                              // expected-note {{previous definition is here}}
+ at end
+ 
+ at 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}}
+}
+ at synthesize what; // expected-note 2 {{'what' declared here}}
+ at end
+
+ at implementation Bar // expected-warning {{cannot find interface declaration for}}
+- (NSString*) what { // expected-error {{expected a type}}
+  return __what; // expected-error {{use of undeclared identifier}}
+}
+ at end





More information about the cfe-commits mailing list