From patchwork Fri Jul 2 16:52:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 57682 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 6B6211007D2 for ; Sat, 3 Jul 2010 02:51:31 +1000 (EST) Received: (qmail 31943 invoked by alias); 2 Jul 2010 16:51:29 -0000 Received: (qmail 31932 invoked by uid 22791); 2 Jul 2010 16:51:28 -0000 X-SWARE-Spam-Status: No, hits=-6.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 02 Jul 2010 16:51:23 +0000 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o62GpMsG028787 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 2 Jul 2010 12:51:22 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o62GpLuu027545 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 2 Jul 2010 12:51:21 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id o62GqQGS001615; Fri, 2 Jul 2010 18:52:26 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id o62GqPTK001613; Fri, 2 Jul 2010 18:52:25 +0200 Date: Fri, 2 Jul 2010 18:52:25 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix -Wunused-but-set-variable issue with vector conversion (PR c++/44780) Message-ID: <20100702165225.GD25077@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-12-10) 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 Hi! For convertible vector types (and some ObjC++ case apparently too) convert_fro_assignment doesn't go through perform_implicit* and thus mark_rvalue_use isn't called. Fixed thusly. Additionally, I've noticed that in a couple of recent -Wunused-but* patched I forgot that mark_[rl]value_use return a value. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2010-07-02 Jakub Jelinek PR c++/44780 * typeck.c (convert_for_assignment): When converting a convertible vector type or objc++ types, call mark_rvalue_use. * typeck2.c (build_m_component_ref): Use return values from mark_rvalue_use or mark_lvalue_use. * class.c (build_base_path): Likewise. * call.c (build_conditional_expr): Likewise. * c-c++-common/Wunused-var-12.c: New test. Jakub --- gcc/cp/typeck.c.jj 2010-07-01 08:45:31.000000000 +0200 +++ gcc/cp/typeck.c 2010-07-02 10:54:59.000000000 +0200 @@ -7211,7 +7211,10 @@ convert_for_assignment (tree type, tree if (TREE_CODE (type) == VECTOR_TYPE && coder == VECTOR_TYPE && vector_types_convertible_p (type, rhstype, true)) - return convert (type, rhs); + { + rhs = mark_rvalue_use (rhs); + return convert (type, rhs); + } if (rhs == error_mark_node || rhstype == error_mark_node) return error_mark_node; @@ -7255,7 +7258,10 @@ convert_for_assignment (tree type, tree } if (objc_compare_types (type, rhstype, parmno, rname)) - return convert (type, rhs); + { + rhs = mark_rvalue_use (rhs); + return convert (type, rhs); + } } /* [expr.ass] --- gcc/cp/typeck2.c.jj 2010-07-01 08:45:31.000000000 +0200 +++ gcc/cp/typeck2.c 2010-07-02 10:55:58.000000000 +0200 @@ -1478,8 +1478,8 @@ build_m_component_ref (tree datum, tree if (error_operand_p (datum) || error_operand_p (component)) return error_mark_node; - mark_lvalue_use (datum); - mark_rvalue_use (component); + datum = mark_lvalue_use (datum); + component = mark_rvalue_use (component); ptrmem_type = TREE_TYPE (component); if (!TYPE_PTR_TO_MEMBER_P (ptrmem_type)) --- gcc/cp/class.c.jj 2010-07-01 08:45:31.000000000 +0200 +++ gcc/cp/class.c 2010-07-02 10:55:29.000000000 +0200 @@ -284,7 +284,7 @@ build_base_path (enum tree_code code, /* This must happen before the call to save_expr. */ expr = cp_build_unary_op (ADDR_EXPR, expr, 0, tf_warning_or_error); else - mark_rvalue_use (expr); + expr = mark_rvalue_use (expr); offset = BINFO_OFFSET (binfo); fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull); --- gcc/cp/call.c.jj 2010-07-01 08:45:31.000000000 +0200 +++ gcc/cp/call.c 2010-07-02 10:56:57.000000000 +0200 @@ -3861,8 +3861,8 @@ build_conditional_expr (tree arg1, tree && same_type_p (arg2_type, arg3_type)) { result_type = arg2_type; - mark_lvalue_use (arg2); - mark_lvalue_use (arg3); + arg2 = mark_lvalue_use (arg2); + arg3 = mark_lvalue_use (arg3); goto valid_operands; } --- gcc/testsuite/c-c++-common/Wunused-var-12.c.jj 2010-07-02 11:10:18.000000000 +0200 +++ gcc/testsuite/c-c++-common/Wunused-var-12.c 2010-07-02 11:07:18.000000000 +0200 @@ -0,0 +1,25 @@ +/* PR c++/44780 */ +/* { dg-do compile } */ +/* { dg-options "-Wunused" } */ + +typedef double vec __attribute__ ((__vector_size__ (16))); +vec c, d; + +void +foo (void) +{ + vec a; + vec b; + a = c; + b = a; + d = b; +} + +void +bar (void) +{ + vec a; + vec b; /* { dg-warning "set but not used" } */ + a = c; + b = a; +}