From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 46083 invoked by alias); 26 Jan 2016 15:21:12 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 46063 invoked by uid 89); 26 Jan 2016 15:21:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2180 X-HELO: mail-yk0-f179.google.com Received: from mail-yk0-f179.google.com (HELO mail-yk0-f179.google.com) (209.85.160.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 26 Jan 2016 15:21:10 +0000 Received: by mail-yk0-f179.google.com with SMTP id k129so203815108yke.0 for ; Tue, 26 Jan 2016 07:21:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=Jlp5/Lw10YVp3yhSMI/SP7M75gPcyPIvkK5rNwBX9G0=; b=hAHbexrDFpDltFZxlPpYrZs/Lu1H5di0N/KkYG57aRFq/CYnfIa4LOWRTn1W1toDeA aSgvUE3aZOYnXLVQX6uN4yKgyRMZU2aKk6E0tUhHmWqEcIkdOWPEouT+Fhq0ix0aIx/T Ao+QJ3bzuma2BSRUZRI6APiVfBDUfyrUjk1UVZca1o6xCnCvdoBLK9n0v46uLmx3lwnl 1hx+s0Wyv+4mQsXbMD3quXWb492rdyPzZG1ohQXwVrD2agr4hZQ3f53vkWQRYLGTRGES t9Mg8vx8FE/wluj35ZQ0QAevFsZuL/wvv3px0PvmTwQQ+Mh1m+WiHMojZqYaeVBN4wQY /EUA== X-Gm-Message-State: AG10YORyUxnk8CBbyiMsF/QbRUTWvaaNbtGU74VMeVHlfcIV8Zw+maOw+rAzmGoq4W5yIbeuI3MjY0Ollvpt/w== MIME-Version: 1.0 X-Received: by 10.37.5.20 with SMTP id 20mr12422034ybf.19.1453821668473; Tue, 26 Jan 2016 07:21:08 -0800 (PST) Received: by 10.37.202.82 with HTTP; Tue, 26 Jan 2016 07:21:08 -0800 (PST) In-Reply-To: <20160125203829.GP3017@tucnak.redhat.com> References: <20160125203829.GP3017@tucnak.redhat.com> Date: Tue, 26 Jan 2016 15:21:00 -0000 Message-ID: Subject: Re: [C PATCH] Fix -Wunused-function (PR debug/66869) From: Richard Biener To: Jakub Jelinek Cc: "Joseph S. Myers" , Marek Polacek , Jason Merrill , Jan Hubicka , GCC Patches Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2016-01/txt/msg01992.txt.bz2 On Mon, Jan 25, 2016 at 9:38 PM, Jakub Jelinek wrote: > Hi! > > The early-debug changes moved warnings about unused functions into cgraph. > The problem is that if we have just unused declarations, they aren't > sometimes even registered with cgraph and therefore we no longer warn. > > Here is an attempt to register those with cgraph anyway to get the warning, > for C FE only (no idea where to do that in C++ FE). Or anyone has better > suggestions what to do? > > Bootstrapped/regtested on x86_64-linux and i686-linux. > > 2016-01-25 Jakub Jelinek > > PR debug/66869 > * c-decl.c (c_write_global_declarations_1): For warn_unused_function, > ensure creation of cgraph node even if there is no definition. > > * gcc.dg/pr66869.c: New test. > > --- gcc/c/c-decl.c.jj 2016-01-21 00:41:47.000000000 +0100 > +++ gcc/c/c-decl.c 2016-01-25 16:36:31.973504082 +0100 > @@ -10741,11 +10741,19 @@ c_write_global_declarations_1 (tree glob > if (TREE_CODE (decl) == FUNCTION_DECL > && DECL_INITIAL (decl) == 0 > && DECL_EXTERNAL (decl) > - && !TREE_PUBLIC (decl) > - && C_DECL_USED (decl)) > + && !TREE_PUBLIC (decl)) > { > - pedwarn (input_location, 0, "%q+F used but never defined", decl); > - TREE_NO_WARNING (decl) = 1; > + if (C_DECL_USED (decl)) > + { > + pedwarn (input_location, 0, "%q+F used but never defined", decl); > + TREE_NO_WARNING (decl) = 1; > + } > + /* For -Wunused-function push the unused statics into cgraph, > + so that check_global_declaration emits the warning. */ > + else if (warn_unused_function > + && ! DECL_ARTIFICIAL (decl) > + && ! TREE_NO_WARNING (decl)) > + cgraph_node::get_create (decl); Err, so why not warn here directly? Richard. > } > > wrapup_global_declaration_1 (decl); > --- gcc/testsuite/gcc.dg/pr66869.c.jj 2016-01-25 16:38:39.037758657 +0100 > +++ gcc/testsuite/gcc.dg/pr66869.c 2016-01-25 16:39:42.346888954 +0100 > @@ -0,0 +1,6 @@ > +/* PR debug/66869 */ > +/* { dg-do compile } */ > +/* { dg-options "-Wunused-function" } */ > + > +static void test (void); /* { dg-warning "'test' declared 'static' but never defined" } */ > +int i; > > Jakub