public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: "Joseph S. Myers" <joseph@codesourcery.com>,
	       Marek Polacek <polacek@redhat.com>,
	Jason Merrill <jason@redhat.com>,
	       Jan Hubicka <hubicka@ucw.cz>,
	GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [C PATCH] Fix -Wunused-function (PR debug/66869)
Date: Wed, 27 Jan 2016 18:52:00 -0000	[thread overview]
Message-ID: <20160127185159.GT3017@tucnak.redhat.com> (raw)
In-Reply-To: <CAFiYyc1Kn++hPBBXw1NcjROxpTJbBdPy4Eu=ZXfMmPkhQ8H0=A@mail.gmail.com>

Hi!

On Wed, Jan 27, 2016 at 11:17:18AM +0100, Richard Biener wrote:
> No, simply warn and set TREE_NO_WARNING so cgraph doesn't warn again.

This seems to work too, bootstrapped/regtested on x86_64-linux and
i686-linux, ok for trunk?

2016-01-25  Jakub Jelinek  <jakub@redhat.com>

	PR debug/66869
	* c-decl.c (c_write_global_declarations_1): Warn with
	warn_unused_function if static prototype without definition
	is not C_DECL_USED.

	* gcc.dg/pr66869.c: New test.

--- gcc/c/c-decl.c.jj	2016-01-25 22:33:11.813025064 +0100
+++ gcc/c/c-decl.c	2016-01-27 13:03:15.896068387 +0100
@@ -10741,11 +10741,22 @@ 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 warn about unused static prototypes.  */
+	  else if (warn_unused_function
+		   && ! DECL_ARTIFICIAL (decl)
+		   && ! TREE_NO_WARNING (decl))
+	    {
+	      warning (OPT_Wunused_function,
+		       "%q+F declared %<static%> but never defined", decl);
+	      TREE_NO_WARNING (decl) = 1;
+	    }
 	}
 
       wrapup_global_declaration_1 (decl);
--- gcc/testsuite/gcc.dg/pr66869.c.jj	2016-01-27 12:59:46.997929005 +0100
+++ gcc/testsuite/gcc.dg/pr66869.c	2016-01-27 12:59:46.997929005 +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

  reply	other threads:[~2016-01-27 18:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-25 20:38 Jakub Jelinek
2016-01-26 15:21 ` Richard Biener
2016-01-26 16:18   ` Jakub Jelinek
2016-01-27 10:17     ` Richard Biener
2016-01-27 18:52       ` Jakub Jelinek [this message]
2016-01-27 19:29         ` Jeff Law
2016-01-28 20:15           ` [C++ " Jakub Jelinek
2016-01-29 10:25             ` Jason Merrill
2016-01-29 10:35               ` Jakub Jelinek
2016-01-29 10:47                 ` Jason Merrill
2016-01-29 12:31                 ` Jakub Jelinek
2016-02-03 16:05                   ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160127185159.GT3017@tucnak.redhat.com \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hubicka@ucw.cz \
    --cc=jason@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=polacek@redhat.com \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).