r229458 - [Objctive-C sema]. Do not do the unused-getter-return-value

Fariborz Jahanian fjahanian at apple.com
Mon Feb 16 15:49:47 PST 2015


Author: fjahanian
Date: Mon Feb 16 17:49:44 2015
New Revision: 229458

URL: http://llvm.org/viewvc/llvm-project?rev=229458&view=rev
Log:
[Objctive-C sema]. Do not do the unused-getter-return-value
warning when property getter is used in direct method call
and return value of property is unused. rdar://19773512

Modified:
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/SemaObjC/unused.m

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=229458&r1=229457&r2=229458&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Mon Feb 16 17:49:44 2015
@@ -2238,9 +2238,7 @@ bool Expr::isUnusedResultAWarning(const
     }
 
     if (const ObjCMethodDecl *MD = ME->getMethodDecl())
-      if (MD->hasAttr<WarnUnusedResultAttr>() ||
-          (MD->isPropertyAccessor() && !MD->getReturnType()->isVoidType() &&
-           !ME->getReceiverType()->isObjCIdType())) {
+      if (MD->hasAttr<WarnUnusedResultAttr>()) {
         WarnE = this;
         Loc = getExprLoc();
         return true;

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=229458&r1=229457&r2=229458&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Mon Feb 16 17:49:44 2015
@@ -265,10 +265,6 @@ void Sema::DiagnoseUnusedExprResult(cons
         Diag(Loc, diag::warn_unused_result) << R1 << R2;
         return;
       }
-      if (MD->isPropertyAccessor()) {
-        Diag(Loc, diag::warn_unused_property_expr);
-        return;
-      }
     }
   } else if (const PseudoObjectExpr *POE = dyn_cast<PseudoObjectExpr>(E)) {
     const Expr *Source = POE->getSyntacticForm();

Modified: cfe/trunk/test/SemaObjC/unused.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/unused.m?rev=229458&r1=229457&r2=229458&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/unused.m (original)
+++ cfe/trunk/test/SemaObjC/unused.m Mon Feb 16 17:49:44 2015
@@ -91,8 +91,7 @@ void rdar15596883(id x) {
 
 void test3(PropertyObject *o)
 {
-  [o length]; // expected-warning {{property access result unused - getters should not be used for side effects}}
-  (void)[o length];
+  [o length]; // No warning. property name used in direct method call.
 }
 
 void test4(id o)
@@ -102,5 +101,30 @@ void test4(id o)
 
 void test5(id <P> p)
 {
-    [p property]; // expected-warning {{property access result unused - getters should not be used for side effects}}
+    [p property]; // No warning. property name used in direct method call.
 }
+
+// rdar://19773512
+ at interface Model
+ at property (nonatomic, retain, setter=setOrCreateGroup:, getter=getOrCreateGroup) id group;
+ at end
+
+ at implementation Model {
+    id _group;
+}
+- (void)method {
+    [self getOrCreateGroup];
+    self.getOrCreateGroup; // expected-warning {{property access result unused - getters should not be used for side effects}}
+    self.group; // expected-warning {{property access result unused - getters should not be used for side effects}}
+    self.group = (void*)0;
+    [self setOrCreateGroup : ((void*)0)];
+    
+}
+- (id)getOrCreateGroup {
+    if (!_group) {
+        _group = @"group";
+    }
+    return _group;
+}
+ at end
+





More information about the cfe-commits mailing list