From patchwork Mon Oct 18 15:00:19 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 68200 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 3A14EB6EF1 for ; Tue, 19 Oct 2010 02:00:58 +1100 (EST) Received: (qmail 23813 invoked by alias); 18 Oct 2010 15:00:51 -0000 Received: (qmail 23801 invoked by uid 22791); 18 Oct 2010 15:00:50 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_TM, 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; Mon, 18 Oct 2010 15:00:31 +0000 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9IF0Lf0001547 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 18 Oct 2010 11:00:21 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o9IF0Jau009182 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 18 Oct 2010 11:00:20 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id o9IF0JLe009773; Mon, 18 Oct 2010 17:00:19 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id o9IF0J0B009772; Mon, 18 Oct 2010 17:00:19 +0200 Date: Mon, 18 Oct 2010 17:00:19 +0200 From: Jakub Jelinek To: "Joseph S. Myers" , Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C/C++ PATCH] Fix -Wunused-but-set* with computed goto (PR c/46015) Message-ID: <20101018150019.GJ18103@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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! As the testcase shows, mark_exp_read wasn't being called on computed goto's argument, leading to spurious -Wunused-but-set* warnings. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2010-10-18 Jakub Jelinek PR c/46015 * c-parser.c (c_parser_statement_after_labels): Call mark_exp_read on computed goto argument. * semantics.c (finish_goto_stmt): Call mark_rvalue_use on computed goto destination. * c-c++-common/Wunused-var-13.c: New test. Jakub --- gcc/c-parser.c.jj 2010-10-07 19:45:22.000000000 +0200 +++ gcc/c-parser.c 2010-10-18 13:34:24.000000000 +0200 @@ -4116,9 +4116,12 @@ c_parser_statement_after_labels (c_parse } else if (c_parser_next_token_is (parser, CPP_MULT)) { + tree val; + c_parser_consume_token (parser); - stmt = c_finish_goto_ptr (loc, - c_parser_expression (parser).value); + val = c_parser_expression (parser).value; + mark_exp_read (val); + stmt = c_finish_goto_ptr (loc, val); } else c_parser_error (parser, "expected identifier or %<*%>"); --- gcc/cp/semantics.c.jj 2010-09-17 14:10:56.000000000 +0200 +++ gcc/cp/semantics.c 2010-10-18 14:00:06.000000000 +0200 @@ -537,6 +537,7 @@ finish_goto_stmt (tree destination) TREE_USED (destination) = 1; else { + destination = mark_rvalue_use (destination); if (!processing_template_decl) { destination = cp_convert (ptr_type_node, destination); --- gcc/testsuite/c-c++-common/Wunused-var-13.c.jj 2010-10-18 14:01:07.000000000 +0200 +++ gcc/testsuite/c-c++-common/Wunused-var-13.c 2010-10-18 14:01:59.000000000 +0200 @@ -0,0 +1,27 @@ +/* PR c/46015 */ +/* { dg-options "-Wunused" } */ +/* { dg-do compile } */ + +int +f1 (int i) +{ + static void *labs[2] = { &&lab1, &&lab2 }; + goto *(labs[i & 1]); + +lab1: + return 1; +lab2: + return 2; +} + +int +f2 (int i) +{ + void *labs[2] = { &&lab1, &&lab2 }; + goto *labs[i & 1]; + +lab1: + return 1; +lab2: + return 2; +}