]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cgraphunit: Avoid code generation differences based on -w/TREE_NO_WARNING [PR94277]
authorJakub Jelinek <jakub@redhat.com>
Tue, 24 Mar 2020 08:33:17 +0000 (09:33 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 24 Mar 2020 08:33:17 +0000 (09:33 +0100)
The following testcase FAILs with -fcompare-debug, but not because -g vs.
-g0 would make a difference, but because the second compilation is done with
-w in order not to emit warnings twice and -w seems to affect the *.gkd dump
content.
This is because TREE_NO_WARNING flag, or warn_unused_function does affect
not just whether a warning/pedwarn is printed, but also whether we set
TREE_PUBLIC on such decls.
The following patch makes sure we set it regardless of anything warning
related (TREE_NO_WARNING or warn_unused_function).

2020-03-24  Jakub Jelinek  <jakub@redhat.com>

PR debug/94277
* cgraphunit.c (check_global_declaration): For DECL_EXTERNAL and
non-TREE_PUBLIC non-DECL_ARTIFICIAL FUNCTION_DECLs, set TREE_PUBLIC
regardless of whether TREE_NO_WARNING is set on it or whether
warn_unused_function is true or not.

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

gcc/ChangeLog
gcc/cgraphunit.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr94277.c [new file with mode: 0644]

index 3b92670395740ba33b14c21058645cb53c896f38..a45d7ba876b40ad60b7cab54231f23f10cf1b767 100644 (file)
@@ -1,3 +1,11 @@
+2020-03-24  Jakub Jelinek  <jakub@redhat.com>
+
+       PR debug/94277
+       * cgraphunit.c (check_global_declaration): For DECL_EXTERNAL and
+       non-TREE_PUBLIC non-DECL_ARTIFICIAL FUNCTION_DECLs, set TREE_PUBLIC
+       regardless of whether TREE_NO_WARNING is set on it or whether
+       warn_unused_function is true or not.
+
 2020-03-23  Jeff Law  <law@redhat.com>
 
        PR rtl-optimization/90275
index d7ed405bf2c2fa3a7fc02d39c0f0b9db38162d60..3415660440e8bdcb20756941f01f6918437f4b45 100644 (file)
@@ -1068,15 +1068,15 @@ check_global_declaration (symtab_node *snode)
       && DECL_INITIAL (decl) == 0
       && DECL_EXTERNAL (decl)
       && ! DECL_ARTIFICIAL (decl)
-      && ! TREE_NO_WARNING (decl)
-      && ! TREE_PUBLIC (decl)
-      && (warn_unused_function
-         || snode->referred_to_p (/*include_self=*/false)))
+      && ! TREE_PUBLIC (decl))
     {
-      if (snode->referred_to_p (/*include_self=*/false))
+      if (TREE_NO_WARNING (decl))
+       ;
+      else if (snode->referred_to_p (/*include_self=*/false))
        pedwarn (input_location, 0, "%q+F used but never defined", decl);
       else
-       warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
+       warning (OPT_Wunused_function, "%q+F declared %<static%> but never "
+                                      "defined", decl);
       /* This symbol is effectively an "extern" declaration now.  */
       TREE_PUBLIC (decl) = 1;
     }
index 28adfd8b580a0e45d6022d8f91819f463544a6a9..13e609015801127d4b5c37289954f51dcad54829 100644 (file)
@@ -1,3 +1,8 @@
+2020-03-24  Jakub Jelinek  <jakub@redhat.com>
+
+       PR debug/94277
+       * gcc.dg/pr94277.c: New test.
+
 2020-03-23  Jeff Law  <law@redhat.com>
 
        PR target/94144
diff --git a/gcc/testsuite/gcc.dg/pr94277.c b/gcc/testsuite/gcc.dg/pr94277.c
new file mode 100644 (file)
index 0000000..dfe38e4
--- /dev/null
@@ -0,0 +1,11 @@
+/* PR debug/94277 */
+/* { dg-do compile } */
+/* { dg-options "-fcompare-debug" } */
+
+static void foo (void);        /* { dg-warning "used but never defined" } */
+
+void
+bar (void)
+{
+  foo ();
+}