]> granicus.if.org Git - clang/commitdiff
Fix crash when assiging to a property with an invalid type
authorOlivier Goffart <ogoffart@woboq.com>
Mon, 4 Aug 2014 17:28:05 +0000 (17:28 +0000)
committerOlivier Goffart <ogoffart@woboq.com>
Mon, 4 Aug 2014 17:28:05 +0000 (17:28 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214734 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaPseudoObject.cpp
test/SemaObjCXX/property-invalid-type.mm [new file with mode: 0644]

index c8d34f84e1b779a95fe890db4fbe112ff894fdb2..fac7774734c0d25035aff739765294a364c76561 100644 (file)
@@ -845,7 +845,12 @@ bool ObjCPropertyOpBuilder::tryBuildGetOfReference(Expr *op,
   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();
diff --git a/test/SemaObjCXX/property-invalid-type.mm b/test/SemaObjCXX/property-invalid-type.mm
new file mode 100644 (file)
index 0000000..e249ace
--- /dev/null
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
+
+@interface I
+{
+  A* response; // expected-error {{unknown type name 'A'}}
+}
+@end
+@interface I ()
+@property A* response;  // expected-error {{unknown type name 'A'}}
+@end
+@implementation I
+@synthesize response;
+- (void) foo :(A*) a   // expected-error {{expected a type}}
+{
+  self.response = a;
+}
+@end
+
+