From patchwork Wed Oct 6 18:21:14 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 66958 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 35605B70D1 for ; Thu, 7 Oct 2010 05:22:07 +1100 (EST) Received: (qmail 22275 invoked by alias); 6 Oct 2010 18:21:48 -0000 Received: (qmail 22252 invoked by uid 22791); 6 Oct 2010 18:21:44 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from c2bthomr09.btconnect.com (HELO mail.btconnect.com) (213.123.20.127) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 06 Oct 2010 18:21:38 +0000 Received: from host81-138-1-83.in-addr.btopenworld.com (EHLO thor.office) ([81.138.1.83]) by c2bthomr09.btconnect.com with ESMTP id AFI41453; Wed, 06 Oct 2010 19:21:19 +0100 (BST) Cc: Jakub Jelinek , Mike Stump , Nicola Pero Message-Id: <14EDD433-885D-49DF-91EE-D0BB6183DAE9@sandoe-acoustics.co.uk> From: IainS To: GCC Patches In-Reply-To: <20101006181400.GJ4127@tyan-ft48-01.lab.bos.redhat.com> Mime-Version: 1.0 (Apple Message framework v936) Subject: Re: [Patch ObjC*] don't warn 'set not used' when an object is a receiver. Date: Wed, 6 Oct 2010 19:21:14 +0100 References: <2D419F6A-9F07-4533-B7FF-A51464F0E118@sandoe-acoustics.co.uk> <20101006181400.GJ4127@tyan-ft48-01.lab.bos.redhat.com> X-Mirapoint-IP-Reputation: reputation=Fair-1, source=Queried, refid=tid=0001.0A0B0302.4CACBE1A.0149, actions=tag X-Junkmail-Signature-Raw: score=unknown, refid=str=0001.0A0B020A.4CACBE20.01CF, ss=1, fgs=0, ip=0.0.0.0, so=2010-07-22 22:03:31, dmn=2009-09-10 00:05:08, mode=single engine X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org On 6 Oct 2010, at 19:14, Jakub Jelinek wrote: > On Wed, Oct 06, 2010 at 07:07:43PM +0100, IainS wrote: >> Index: gcc/objc/objc-act.c >> =================================================================== >> --- gcc/objc/objc-act.c (revision 165023) >> +++ gcc/objc/objc-act.c (working copy) >> @@ -6409,7 +6409,7 @@ objc_build_message_expr (tree mess) >> method_params = args; >> } >> #endif >> - >> + >> #ifdef OBJCPLUS >> if (processing_template_decl) >> /* Must wait until template instantiation time. */ >> @@ -6455,6 +6455,13 @@ objc_finish_message_expr (tree receiver, >> tree sel_ >> tree selector, retval, class_tree; >> int self, super, have_cast; >> >> + /* If we have an instance, then it has been used/read. */ >> + if (TREE_CODE (receiver) == VAR_DECL) >> + { >> + TREE_USED (receiver) = 1; >> + DECL_READ_P (receiver) = 1; >> + } >> + > > I think you should just do > mark_exp_read (receiver); > instead. thanks Jakub, OK now? amended: > >> --- gcc/testsuite/objc.dg/set-not-used-1.m (revision 0) >> +++ gcc/testsuite/objc.dg/set-not-used-1.m (revision 0) >> @@ -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]; >> +} >> Index: gcc/testsuite/obj-c++.dg/set-not-used-1.mm >> =================================================================== >> --- gcc/testsuite/obj-c++.dg/set-not-used-1.mm (revision 0) >> +++ gcc/testsuite/obj-c++.dg/set-not-used-1.mm (revision 0) >> @@ -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]; >> +} > > Jakub Index: gcc/objc/objc-act.c =================================================================== --- gcc/objc/objc-act.c (revision 165023) +++ gcc/objc/objc-act.c (working copy) @@ -6409,7 +6409,7 @@ objc_build_message_expr (tree mess) method_params = args; } #endif - + #ifdef OBJCPLUS if (processing_template_decl) /* Must wait until template instantiation time. */ @@ -6455,6 +6455,9 @@ objc_finish_message_expr (tree receiver, tree sel_ tree selector, retval, class_tree; int self, super, have_cast; + /* If we have an instance, then it has been used/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). */