From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24032 invoked by alias); 25 Jan 2016 20:38:39 -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 24016 invoked by uid 89); 25 Jan 2016 20:38:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1954, sk:check_g X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 25 Jan 2016 20:38:37 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 9A65DA0776; Mon, 25 Jan 2016 20:38:36 +0000 (UTC) Received: from tucnak.zalov.cz ([10.3.113.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0PKcYM5009168 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 25 Jan 2016 15:38:35 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u0PKcVf1024310; Mon, 25 Jan 2016 21:38:32 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u0PKcTCu024309; Mon, 25 Jan 2016 21:38:29 +0100 Date: Mon, 25 Jan 2016 20:38:00 -0000 From: Jakub Jelinek To: "Joseph S. Myers" , Marek Polacek , Jason Merrill , Jan Hubicka Cc: gcc-patches@gcc.gnu.org Subject: [C PATCH] Fix -Wunused-function (PR debug/66869) Message-ID: <20160125203829.GP3017@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes X-SW-Source: 2016-01/txt/msg01922.txt.bz2 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); } 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