ipa/94947 - fix test for externally visible variables for IPA PTA
authorRichard Biener <rguenther@suse.de>
Tue, 5 May 2020 11:09:50 +0000 (13:09 +0200)
committerRichard Biener <rguenther@suse.de>
Tue, 5 May 2020 12:41:15 +0000 (14:41 +0200)
This fixes lack of an escape point of externally declared variables.

2020-05-05  Richard Biener  <rguenther@suse.de>

PR ipa/94947
* tree-ssa-structalias.c (ipa_pta_execute): Use
varpool_node::externally_visible_p ().
(refered_from_nonlocal_var): Likewise.

* gcc.dg/torture/pr94947-1.c: New testcase.
* gcc.dg/torture/pr94947-2.c: Likewise.

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr94947-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr94947-2.c [new file with mode: 0644]
gcc/tree-ssa-structalias.c

index 71977b57e6e1ef145677b43ace25c51925d71974..9178e9d14c826642d49c265e999a58a81053be7c 100644 (file)
@@ -1,3 +1,10 @@
+2020-05-05  Richard Biener  <rguenther@suse.de>
+
+       PR ipa/94947
+       * tree-ssa-structalias.c (ipa_pta_execute): Use
+       varpool_node::externally_visible_p ().
+       (refered_from_nonlocal_var): Likewise.
+
 2020-05-05  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc.c (LTO_PLUGIN_SPEC): Define if not already.
index 7f973949a7fd31cefdf55881110d4058e96b0fcb..eb81b0ac433ce21e7d36052901151ff5783e6569 100644 (file)
@@ -1,3 +1,9 @@
+2020-05-05  Richard Biener  <rguenther@suse.de>
+
+       PR ipa/94947
+       * gcc.dg/torture/pr94947-1.c: New testcase.
+       * gcc.dg/torture/pr94947-2.c: Likewise.
+
 2020-05-05  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/aggr29.adb: New test.
diff --git a/gcc/testsuite/gcc.dg/torture/pr94947-1.c b/gcc/testsuite/gcc.dg/torture/pr94947-1.c
new file mode 100644 (file)
index 0000000..ab8b488
--- /dev/null
@@ -0,0 +1,23 @@
+/* { dg-do run } */
+/* { dg-additional-sources "pr94947-2.c" } */
+/* { dg-additional-options "-fipa-pta -flto-partition=1to1" } */
+
+extern void abort ();
+extern void baz ();
+extern void (*baz_call)();
+static int *p;
+
+static void foo ()
+{
+  if (*p != 1)
+    abort ();
+}
+
+int main()
+{
+  int x = 1;
+  p = &x;
+  baz_call = foo;
+  baz ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr94947-2.c b/gcc/testsuite/gcc.dg/torture/pr94947-2.c
new file mode 100644 (file)
index 0000000..670dd61
--- /dev/null
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+
+void (*baz_call)();
+void baz ()
+{
+  baz_call ();
+}
index 416a26c996cc2300115047aec56fd0bda1e13375..e9fcafd9b34080a9b959c80a493d4fc1bbf13735 100644 (file)
@@ -8097,7 +8097,7 @@ refered_from_nonlocal_var (struct varpool_node *node, void *data)
 {
   bool *nonlocal_p = (bool *)data;
   *nonlocal_p |= (node->used_from_other_partition
-                 || node->externally_visible
+                 || node->externally_visible_p ()
                  || node->force_output);
   return false;
 }
@@ -8187,8 +8187,8 @@ ipa_pta_execute (void)
 
       /* For the purpose of IPA PTA unit-local globals are not
          escape points.  */
-      bool nonlocal_p = (var->used_from_other_partition
-                        || var->externally_visible
+      bool nonlocal_p = (var->externally_visible_p ()
+                        || var->used_from_other_partition
                         || var->force_output);
       var->call_for_symbol_and_aliases (refered_from_nonlocal_var,
                                        &nonlocal_p, true);