From patchwork Thu Nov 7 03:53:22 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingjie Xing X-Patchwork-Id: 289176 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 54EEB2C0336 for ; Thu, 7 Nov 2013 14:53:44 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; q=dns; s=default; b=xko9z5gGydXPIx3j+u WMssVfRi1Dm2ei0EI1i96Oua4N/qwTkpopz2uclWztrSukFaMcz6RblM3ENc0zpU j9d4JPd10pXI7nXsCXF1zFAJAqv6OiKBPd2xr/2tnZqq2JPKGsqpVcFJYazkTROB VZhnyr5HOKuMCQWys0iV/htsE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; s=default; bh=xnj3PkgLvJkFhltmlNmLpanW aaM=; b=shIAtNd56EPZGH3Z7N5ukoGJDwy0c2FgKRXYCRAwmzKnrg8lW43YyMOx 9Od2nHrPrkEz0RjbE8YyqA/204ZuVTsc/hPt2notUueqx8RsbuoRJ6c6qB/A5LGx Nu05wL8vFPTSnlqbd5/AMMh+cHQyyQpxQ/bDchOock4r+diIUG4= Received: (qmail 7149 invoked by alias); 7 Nov 2013 03:53:33 -0000 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 Received: (qmail 7135 invoked by uid 89); 7 Nov 2013 03:53:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.0 required=5.0 tests=AWL, BAYES_50, FREEMAIL_FROM, RDNS_NONE, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-ie0-f171.google.com Received: from Unknown (HELO mail-ie0-f171.google.com) (209.85.223.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 07 Nov 2013 03:53:31 +0000 Received: by mail-ie0-f171.google.com with SMTP id tp5so786501ieb.16 for ; Wed, 06 Nov 2013 19:53:23 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.50.131.163 with SMTP id on3mr628256igb.46.1383796402952; Wed, 06 Nov 2013 19:53:22 -0800 (PST) Received: by 10.50.51.101 with HTTP; Wed, 6 Nov 2013 19:53:22 -0800 (PST) In-Reply-To: References: Date: Thu, 7 Nov 2013 11:53:22 +0800 Message-ID: Subject: Re: [C] Fix PR57258: unused variable warning is emitted for volatile variables From: Mingjie Xing To: Richard Biener , "Joseph S. Myers" Cc: gcc-patches X-IsSubscribed: yes 2013/11/6 Richard Biener : > You miss a testcase. > > Also why should the warning be omitted for unused automatic > volatile variables? They cannot be used in any way. > > Richard. Thanks. I've updated the patch with a test case. c/ChangeLog PR 57258 * c-decl.c (pop_scope): Don't emit unused variable warnings for accessed volatile variables. testsuite/ChangeLog * gcc.dg/Wunused-var-4.c: New test. Mingjie Index: c/c-decl.c =================================================================== --- c/c-decl.c (revision 204285) +++ c/c-decl.c (working copy) @@ -1187,11 +1187,17 @@ pop_scope (void) && scope != external_scope) { if (!TREE_USED (p)) - warning (OPT_Wunused_variable, "unused variable %q+D", p); + { + if (!TREE_THIS_VOLATILE (p) || !DECL_INITIAL (p)) + warning (OPT_Wunused_variable, "unused variable %q+D", p); + } else if (DECL_CONTEXT (p) == current_function_decl) - warning_at (DECL_SOURCE_LOCATION (p), - OPT_Wunused_but_set_variable, - "variable %qD set but not used", p); + { + if (!TREE_THIS_VOLATILE (p)) + warning_at (DECL_SOURCE_LOCATION (p), + OPT_Wunused_but_set_variable, + "variable %qD set but not used", p); + } } if (b->inner_comp)