do not emit bogus set-not-used warnings for objc* entities used as message receivers.
authoriains <iains@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 7 Oct 2010 14:05:24 +0000 (14:05 +0000)
committeriains <iains@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 7 Oct 2010 14:05:24 +0000 (14:05 +0000)
gcc/objc:
* objc-act.c (objc_build_message_expr):  Call mark_exp_read () to signal that
the receiver has been used.
gcc/testsuite:
* objc.dg/set-not-used-1.m: New
* obj-c++.dg/set-not-used-1.mm: New.

git-svn-id: svn://gcc.gnu.org/svn/gcc/trunk@165111 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/objc/ChangeLog
gcc/objc/objc-act.c
gcc/testsuite/ChangeLog
gcc/testsuite/obj-c++.dg/set-not-used-1.mm [new file with mode: 0644]
gcc/testsuite/objc.dg/set-not-used-1.m [new file with mode: 0644]

index e075f93..27de164 100644 (file)
@@ -1,3 +1,8 @@
+2010-10-07  Iain Sandoe  <iains@gcc.gnu.org>
+
+       * objc-act.c (objc_build_message_expr):  Call mark_exp_read () to signal that
+       the receiver has been used.
+
 2010-10-06  Nicola Pero  <nicola.pero@meta-innovation.com>
 
        * README: Obsolete file removed.
index 730efba..e1dca58 100644 (file)
@@ -6455,6 +6455,9 @@ objc_finish_message_expr (tree receiver, tree sel_name, tree method_params)
   tree selector, retval, class_tree;
   int self, super, have_cast;
 
+  /* We have used the receiver, so mark it as read.  */
+  mark_exp_read (receiver);
+
   /* Extract the receiver of the message, as well as its type
      (where the latter may take the form of a cast or be inferred
      from the implementation context).  */
index a07e2e4..f78e496 100644 (file)
@@ -1,3 +1,8 @@
+2010-10-07  Iain Sandoe  <iains@gcc.gnu.org>
+
+       * objc.dg/set-not-used-1.m: New
+       * obj-c++.dg/set-not-used-1.mm: New.
+
 2010-10-07  Iain Sandoe  <iains@gcc.gnu.org>
 
        * objc.dg/attributes/method-attribute-3.m: New.
diff --git a/gcc/testsuite/obj-c++.dg/set-not-used-1.mm b/gcc/testsuite/obj-c++.dg/set-not-used-1.mm
new file mode 100644 (file)
index 0000000..6380ec9
--- /dev/null
@@ -0,0 +1,36 @@
+
+/* { dg-do compile } */
+/* { dg-options "-Wunused-but-set-variable" } */
+
+#import "../objc-obj-c++-shared/Object1.h"
+#include <objc/objc-api.h>
+
+@interface obj : Object
+{
+  int value;
+}
+- (int) value;
+- (void) setValue: (int)number;
+@end
+
+@implementation obj : Object
+
+- (int) value { return value; }
+- (void) setValue: (int)number { value = number; }
+
+@end
+
+int main (void)
+{
+  obj *a;              /* { dg-bogus "set but not used" } */
+  obj *b;              /* { dg-bogus "set but not used" } */
+  obj *c;              /* { dg-warning "set but not used" } */
+
+  a = [obj new];
+  b = [obj new];
+  c = [obj new];
+
+  [b setValue: [a value]];
+
+  return [a value];
+}
diff --git a/gcc/testsuite/objc.dg/set-not-used-1.m b/gcc/testsuite/objc.dg/set-not-used-1.m
new file mode 100644 (file)
index 0000000..6380ec9
--- /dev/null
@@ -0,0 +1,36 @@
+
+/* { dg-do compile } */
+/* { dg-options "-Wunused-but-set-variable" } */
+
+#import "../objc-obj-c++-shared/Object1.h"
+#include <objc/objc-api.h>
+
+@interface obj : Object
+{
+  int value;
+}
+- (int) value;
+- (void) setValue: (int)number;
+@end
+
+@implementation obj : Object
+
+- (int) value { return value; }
+- (void) setValue: (int)number { value = number; }
+
+@end
+
+int main (void)
+{
+  obj *a;              /* { dg-bogus "set but not used" } */
+  obj *b;              /* { dg-bogus "set but not used" } */
+  obj *c;              /* { dg-warning "set but not used" } */
+
+  a = [obj new];
+  b = [obj new];
+  c = [obj new];
+
+  [b setValue: [a value]];
+
+  return [a value];
+}