summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2016-01-27 19:32:49 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2016-01-27 19:32:49 +0000
commit78e516ebb11c4bf359ccd08cba14e16c0a5152db (patch)
tree25b41720693a07d6c651306b4666907bbb307799
parent7deb975a881f0dae3c84b107a6776114c4f7a318 (diff)
downloadgcc-78e516ebb11c4bf359ccd08cba14e16c0a5152db.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@232899 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/c/ChangeLog7
-rw-r--r--gcc/c/c-decl.c19
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/pr66869.c6
4 files changed, 33 insertions, 4 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 7999d2a987a..5341f044d28 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,10 @@
+2016-01-27 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.
+
2016-01-27 Marek Polacek <polacek@redhat.com>
PR c/68062
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 1ec60420db9..502fa5c7056 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -10741,11 +10741,22 @@ c_write_global_declarations_1 (tree globals)
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);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 22a124a1ab3..1ee941396ce 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2016-01-27 Jakub Jelinek <jakub@redhat.com>
+
+ PR debug/66869
+ * gcc.dg/pr66869.c: New test.
+
2016-01-25 Jeff Law <law@redhat.com>
PR tree-optimization/68398
diff --git a/gcc/testsuite/gcc.dg/pr66869.c b/gcc/testsuite/gcc.dg/pr66869.c
new file mode 100644
index 00000000000..916d1419982
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr66869.c
@@ -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;