From: iains Date: Thu, 7 Oct 2010 14:05:24 +0000 (+0000) Subject: do not emit bogus set-not-used warnings for objc* entities used as message receivers. X-Git-Tag: upstream/4.9.2~26036 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b79b475d0dd7fe7d492035c2c05b5c5a83ed7639;p=platform%2Fupstream%2Flinaro-gcc.git do not emit bogus set-not-used warnings for objc* entities used as message receivers. 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+ssh://gcc.gnu.org/svn/gcc/trunk@165111 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog index e075f93..27de164 100644 --- a/gcc/objc/ChangeLog +++ b/gcc/objc/ChangeLog @@ -1,3 +1,8 @@ +2010-10-07 Iain Sandoe + + * objc-act.c (objc_build_message_expr): Call mark_exp_read () to signal that + the receiver has been used. + 2010-10-06 Nicola Pero * README: Obsolete file removed. diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index 730efba..e1dca58 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -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). */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a07e2e4..f78e496 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2010-10-07 Iain Sandoe + * objc.dg/set-not-used-1.m: New + * obj-c++.dg/set-not-used-1.mm: New. + +2010-10-07 Iain Sandoe + * objc.dg/attributes/method-attribute-3.m: New. * obj-c++.dg/attributes/method-attribute-3.mm: 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 index 0000000..6380ec9 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/set-not-used-1.mm @@ -0,0 +1,36 @@ + +/* { dg-do compile } */ +/* { dg-options "-Wunused-but-set-variable" } */ + +#import "../objc-obj-c++-shared/Object1.h" +#include + +@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 index 0000000..6380ec9 --- /dev/null +++ b/gcc/testsuite/objc.dg/set-not-used-1.m @@ -0,0 +1,36 @@ + +/* { dg-do compile } */ +/* { dg-options "-Wunused-but-set-variable" } */ + +#import "../objc-obj-c++-shared/Object1.h" +#include + +@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]; +}