[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-commits
Subject:    Re: [PATCH] Fix crash when assiging to a property with an invalid type
From:       Olivier Goffart <ogoffart () kde ! org>
Date:       2014-07-30 13:54:14
Message-ID: 10848537.SzsfFbaoHp () finn
[Download RAW message or body]

On Wednesday 30 July 2014 09:42:40 Olivier Goffart wrote:
> Hi,
> 
> Attached you will find a fix for a crash I have when parsing objective C
> with missing include.
> This is a regression against clang 3.4 which did not crash.
> 
> My approach here is naive and just fixes the symptoms (the crash).

Hi,

Actually I found another similar but unrelated crash. and here is a second 
patch
(The test of this patch is based on the test of the previous patch)

-- 
Olivier
["0002-Fix-crash-when-accessing-a-property-of-an-invalid-in.patch" (0002-Fix-crash-when-accessing-a-property-of-an-invalid-in.patch)]

From f091f191c000ae08cc8fb6e43651b0c0108cedc5 Mon Sep 17 00:00:00 2001
From: Olivier Goffart <ogoffart@woboq.com>
Date: Wed, 30 Jul 2014 15:47:53 +0200
Subject: [PATCH 2/2] Fix crash when accessing a property of an invalid
 interface

---
 lib/Sema/SemaPseudoObject.cpp            | 22 ++++++++++------------
 test/SemaObjCXX/property-invalid-type.mm |  6 +++++-
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/lib/Sema/SemaPseudoObject.cpp b/lib/Sema/SemaPseudoObject.cpp
index fac7774..aa3e89e 100644
--- a/lib/Sema/SemaPseudoObject.cpp
+++ b/lib/Sema/SemaPseudoObject.cpp
@@ -284,7 +284,7 @@ namespace {
     bool tryBuildGetOfReference(Expr *op, ExprResult &result);
     bool findSetter(bool warn=true);
     bool findGetter();
-    bool DiagnoseUnsupportedPropertyUse();
+    void DiagnoseUnsupportedPropertyUse();
 
     Expr *rebuildAndCaptureObject(Expr *syntacticBase) override;
     ExprResult buildGet() override;
@@ -642,7 +642,7 @@ bool ObjCPropertyOpBuilder::findSetter(bool warn) {
   return false;
 }
 
-bool ObjCPropertyOpBuilder::DiagnoseUnsupportedPropertyUse() {
+void ObjCPropertyOpBuilder::DiagnoseUnsupportedPropertyUse() {
   if (S.getCurLexicalContext()->isObjCContainer() &&
       S.getCurLexicalContext()->getDeclKind() != Decl::ObjCCategoryImpl &&
       S.getCurLexicalContext()->getDeclKind() != Decl::ObjCImplementation) {
@@ -650,10 +650,8 @@ bool ObjCPropertyOpBuilder::DiagnoseUnsupportedPropertyUse() {
         S.Diag(RefExpr->getLocation(),
                diag::err_property_function_in_objc_container);
         S.Diag(prop->getLocation(), diag::note_property_declare);
-        return true;
     }
   }
-  return false;
 }
 
 /// Capture the base object of an Objective-C property expression.
@@ -679,10 +677,10 @@ Expr *ObjCPropertyOpBuilder::rebuildAndCaptureObject(Expr *syntacticBase) {
 /// Load from an Objective-C property reference.
 ExprResult ObjCPropertyOpBuilder::buildGet() {
   findGetter();
-  if (!Getter && DiagnoseUnsupportedPropertyUse())
-      return ExprError();
-
-  assert(Getter);
+  if (!Getter) {
+    DiagnoseUnsupportedPropertyUse();
+    return ExprError();
+  }
 
   if (SyntacticRefExpr)
     SyntacticRefExpr->setIsMessagingGetter();
@@ -720,10 +718,10 @@ ExprResult ObjCPropertyOpBuilder::buildGet() {
 ///   value being set as the value of the property operation.
 ExprResult ObjCPropertyOpBuilder::buildSet(Expr *op, SourceLocation opcLoc,
                                            bool captureSetValueAsResult) {
-  bool hasSetter = findSetter(false);
-  if (!hasSetter && DiagnoseUnsupportedPropertyUse())
-      return ExprError();
-  assert(hasSetter); (void) hasSetter;
+  if (!findSetter(false)) {
+    DiagnoseUnsupportedPropertyUse();
+    return ExprError();
+  }
 
   if (SyntacticRefExpr)
     SyntacticRefExpr->setIsMessagingSetter();
diff --git a/test/SemaObjCXX/property-invalid-type.mm b/test/SemaObjCXX/property-invalid-type.mm
index e249ace..5b8a848 100644
--- a/test/SemaObjCXX/property-invalid-type.mm
+++ b/test/SemaObjCXX/property-invalid-type.mm
@@ -7,6 +7,7 @@
 @end
 @interface I ()
 @property A* response;  // expected-error {{unknown type name 'A'}}
+@property  int helper;
 @end
 @implementation I
 @synthesize response;
@@ -16,4 +17,7 @@
 }
 @end
 
-
+void foo(I *i)
+{
+  i.helper;
+}
-- 
2.0.3



_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic