[cfe-commits] r91474 - in /cfe/trunk: include/clang/AST/Expr.h include/clang/Basic/DiagnosticSemaKinds.td lib/AST/Expr.cpp lib/Sema/SemaExpr.cpp test/SemaObjC/property-not-lvalue.m

Fariborz Jahanian fjahanian at apple.com
Tue Dec 15 15:59:41 PST 2009


Author: fjahanian
Date: Tue Dec 15 17:59:41 2009
New Revision: 91474

URL: http://llvm.org/viewvc/llvm-project?rev=91474&view=rev
Log:
Diagnose attempting to assign to a sub-structure of an ivar
using objective-c property. (fixes radar 7449707)


Added:
    cfe/trunk/test/SemaObjC/property-not-lvalue.m
Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=91474&r1=91473&r2=91474&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Dec 15 17:59:41 2009
@@ -156,7 +156,8 @@
     LV_IncompleteVoidType,
     LV_DuplicateVectorComponents,
     LV_InvalidExpression,
-    LV_MemberFunction
+    LV_MemberFunction,
+    LV_SubObjCPropertySetting
   };
   isLvalueResult isLvalue(ASTContext &Ctx) const;
 
@@ -185,7 +186,8 @@
     MLV_NotBlockQualified,
     MLV_ReadonlyProperty,
     MLV_NoSetterProperty,
-    MLV_MemberFunction
+    MLV_MemberFunction,
+    MLV_SubObjCPropertySetting
   };
   isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx,
                                               SourceLocation *Loc = 0) const;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=91474&r1=91473&r2=91474&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Dec 15 17:59:41 2009
@@ -1704,6 +1704,8 @@
   "ISO C does not support '~' for complex conjugation of %0">;
 def error_nosetter_property_assignment : Error<
   "setter method is needed to assign to object using property" " assignment syntax">;
+def error_no_subobject_property_setting : Error<
+  "cannot assign to a sub-structure of an ivar using property" " assignment syntax">;
 
 def ext_freestanding_complex : Extension<
   "complex numbers are an extension in a freestanding C99 implementation">;

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=91474&r1=91473&r2=91474&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Dec 15 17:59:41 2009
@@ -1047,8 +1047,13 @@
 
       //   -- If E2 is a non-static data member [...]. If E1 is an
       //      lvalue, then E1.E2 is an lvalue.
-      if (isa<FieldDecl>(Member))
-        return m->isArrow() ? LV_Valid : m->getBase()->isLvalue(Ctx);
+      if (isa<FieldDecl>(Member)) {
+        if (m->isArrow())
+          return LV_Valid;
+        Expr *BaseExp = m->getBase();
+        return (BaseExp->getStmtClass() == ObjCPropertyRefExprClass) ?
+                 LV_SubObjCPropertySetting : BaseExp->isLvalue(Ctx);        
+      }
 
       //   -- If it refers to a static member function [...], then
       //      E1.E2 is an lvalue.
@@ -1065,9 +1070,13 @@
         // Not an lvalue.
       return LV_InvalidExpression;
     }
-
+    
     // C99 6.5.2.3p4
-    return m->isArrow() ? LV_Valid : m->getBase()->isLvalue(Ctx);
+    if (m->isArrow())
+      return LV_Valid;
+    Expr *BaseExp = m->getBase();
+    return (BaseExp->getStmtClass() == ObjCPropertyRefExprClass) ?
+             LV_SubObjCPropertySetting : BaseExp->isLvalue(Ctx);
   }
   case UnaryOperatorClass:
     if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Deref)
@@ -1244,6 +1253,7 @@
     }
     return MLV_InvalidExpression;
   case LV_MemberFunction: return MLV_MemberFunction;
+    case LV_SubObjCPropertySetting: return MLV_SubObjCPropertySetting;
   }
 
   // The following is illegal:

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=91474&r1=91473&r2=91474&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Dec 15 17:59:41 2009
@@ -5573,6 +5573,9 @@
   case Expr::MLV_NoSetterProperty:
     Diag = diag::error_nosetter_property_assignment;
     break;
+  case Expr::MLV_SubObjCPropertySetting:
+    Diag = diag::error_no_subobject_property_setting;
+    break;
   }
 
   SourceRange Assign;

Added: cfe/trunk/test/SemaObjC/property-not-lvalue.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-not-lvalue.m?rev=91474&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/property-not-lvalue.m (added)
+++ cfe/trunk/test/SemaObjC/property-not-lvalue.m Tue Dec 15 17:59:41 2009
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+typedef struct NSSize {
+     		int width;
+		struct {
+		  int dim;
+		} inner;
+} NSSize;
+
+ at interface Foo  {
+        NSSize _size;
+}
+ at property NSSize size;
+ at end
+
+void foo() { 
+        Foo *f;
+        f.size.width = 2.2; // expected-error {{cannot assign to a sub-structure of an ivar using property assignment syntax}}
+	f.size.inner.dim = 200; // expected-error {{cannot assign to a sub-structure of an ivar using property assignment syntax}}
+}





More information about the cfe-commits mailing list