public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C PATCH] Fix -Wunused-function (PR debug/66869)
@ 2016-01-25 20:38 Jakub Jelinek
  2016-01-26 15:21 ` Richard Biener
  0 siblings, 1 reply; 12+ messages in thread
From: Jakub Jelinek @ 2016-01-25 20:38 UTC (permalink / raw)
  To: Joseph S. Myers, Marek Polacek, Jason Merrill, Jan Hubicka; +Cc: gcc-patches

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  <jakub@redhat.com>

	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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-02-03 16:05 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-25 20:38 [C PATCH] Fix -Wunused-function (PR debug/66869) 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
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

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).