diff mbox

[C] Fix -Wunused-function (PR debug/66869)

Message ID 20160127185159.GT3017@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Jan. 27, 2016, 6:51 p.m. UTC
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.



	Jakub

Comments

Jeff Law Jan. 27, 2016, 7:28 p.m. UTC | #1
On 01/27/2016 11:51 AM, Jakub Jelinek wrote:
> 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.
OK.
jeff
diff mbox

Patch

--- 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;