r214734 - Fix crash when assiging to a property with an invalid type

Olivier Goffart ogoffart at woboq.com
Mon Aug 4 10:28:06 PDT 2014


Author: ogoffart
Date: Mon Aug  4 12:28:05 2014
New Revision: 214734

URL: http://llvm.org/viewvc/llvm-project?rev=214734&view=rev
Log:
Fix crash when assiging to a property with an invalid type

This is a regression from clang 3.4

Set the result to ExprError and returns true, rather than simply
returns false because errors have been reported already and returning
false show a confusing error

Added:
    cfe/trunk/test/SemaObjCXX/property-invalid-type.mm
Modified:
    cfe/trunk/lib/Sema/SemaPseudoObject.cpp

Modified: cfe/trunk/lib/Sema/SemaPseudoObject.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaPseudoObject.cpp?rev=214734&r1=214733&r2=214734&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaPseudoObject.cpp (original)
+++ cfe/trunk/lib/Sema/SemaPseudoObject.cpp Mon Aug  4 12:28:05 2014
@@ -845,7 +845,12 @@ bool ObjCPropertyOpBuilder::tryBuildGetO
   if (!S.getLangOpts().CPlusPlus) return false;
 
   findGetter();
-  assert(Getter && "property has no setter and no getter!");
+  if (!Getter) {
+    // The property has no setter and no getter! This can happen if the type is
+    // invalid. Error have already been reported.
+    result = ExprError();
+    return true;
+  }
 
   // Only do this if the getter returns an l-value reference type.
   QualType resultType = Getter->getReturnType();

Added: cfe/trunk/test/SemaObjCXX/property-invalid-type.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/property-invalid-type.mm?rev=214734&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/property-invalid-type.mm (added)
+++ cfe/trunk/test/SemaObjCXX/property-invalid-type.mm Mon Aug  4 12:28:05 2014
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
+
+ at interface I
+{
+  A* response; // expected-error {{unknown type name 'A'}}
+}
+ at end
+ at interface I ()
+ at property A* response;  // expected-error {{unknown type name 'A'}}
+ at end
+ at implementation I
+ at synthesize response;
+- (void) foo :(A*) a   // expected-error {{expected a type}}
+{
+  self.response = a;
+}
+ at end
+
+





More information about the cfe-commits mailing list