diff mbox

Fix PR64684

Message ID alpine.LSU.2.11.1501201251250.12482@zhemvz.fhfr.qr
State New
Headers show

Commit Message

Richard Biener Jan. 20, 2015, 11:53 a.m. UTC
This fixes PR64684 where a call to is_proper_for_analysis lead to
adding a variable to all_module_statics before it was disabled
via ignore_module_statics.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Richard.

2015-01-20  Richard Biener  <rguenther@suse.de>

	PR ipa/64684
	* ipa-reference.c (add_static_var): Inline ...
	(analyze_function): ... here after splitting out from ...
	(is_proper_for_analysis): ... this.

	* gcc.dg/lto/pr64684_0.c: New testcase.
	* gcc.dg/lto/pr64684_1.c: Likewise.
	* gcc.dg/lto/pr64684_2.c: Likewise.
	* gcc.dg/lto/pr64685_0.c: Likewise.
	* gcc.dg/lto/pr64685_1.c: Likewise.
diff mbox

Patch

Index: gcc/ipa-reference.c
===================================================================
--- gcc/ipa-reference.c	(revision 219884)
+++ gcc/ipa-reference.c	(working copy)
@@ -236,21 +236,6 @@  ipa_reference_get_not_written_global (st
 }
 
 
-
-/* Add VAR to all_module_statics and the two
-   reference_vars_to_consider* sets.  */
-
-static inline void
-add_static_var (tree var)
-{
-  int uid = DECL_UID (var);
-  gcc_assert (TREE_CODE (var) == VAR_DECL);
-  if (dump_file)
-    splay_tree_insert (reference_vars_to_consider,
-		       uid, (splay_tree_value)var);
-  bitmap_set_bit (all_module_statics, uid);
-}
-
 /* Return true if the variable T is the right kind of static variable to
    perform compilation unit scope escape analysis.  */
 
@@ -285,12 +270,6 @@  is_proper_for_analysis (tree t)
   if (bitmap_bit_p (ignore_module_statics, DECL_UID (t)))
     return false;
 
-  /* This is a variable we care about.  Check if we have seen it
-     before, and if not add it the set of variables we care about.  */
-  if (all_module_statics
-      && !bitmap_bit_p (all_module_statics, DECL_UID (t)))
-    add_static_var (t);
-
   return true;
 }
 
@@ -497,6 +476,15 @@  analyze_function (struct cgraph_node *fn
       var = ref->referred->decl;
       if (!is_proper_for_analysis (var))
 	continue;
+      /* This is a variable we care about.  Check if we have seen it
+	 before, and if not add it the set of variables we care about.  */
+      if (all_module_statics
+	  && bitmap_set_bit (all_module_statics, DECL_UID (var)))
+	{
+	  if (dump_file)
+	    splay_tree_insert (reference_vars_to_consider,
+			       DECL_UID (var), (splay_tree_value)var);
+	}
       switch (ref->use)
 	{
 	case IPA_REF_LOAD:
Index: gcc/testsuite/gcc.dg/lto/pr64684_0.c
===================================================================
--- gcc/testsuite/gcc.dg/lto/pr64684_0.c	(revision 0)
+++ gcc/testsuite/gcc.dg/lto/pr64684_0.c	(working copy)
@@ -0,0 +1,13 @@ 
+/* { dg-lto-do run } */
+/* { dg-lto-options { { -O1 -flto } } } */
+
+extern void fn2 (void);
+extern int a;
+
+void
+fn1 ()
+{
+  a = -1;
+  fn2 ();
+  a &= 1;
+}
Index: gcc/testsuite/gcc.dg/lto/pr64684_1.c
===================================================================
--- gcc/testsuite/gcc.dg/lto/pr64684_1.c	(revision 0)
+++ gcc/testsuite/gcc.dg/lto/pr64684_1.c	(working copy)
@@ -0,0 +1,9 @@ 
+/* { dg-options "-Os" } */
+
+extern int a;
+
+void
+fn2 (void)
+{
+  a = 0;
+}
Index: gcc/testsuite/gcc.dg/lto/pr64684_2.c
===================================================================
--- gcc/testsuite/gcc.dg/lto/pr64684_2.c	(revision 0)
+++ gcc/testsuite/gcc.dg/lto/pr64684_2.c	(working copy)
@@ -0,0 +1,16 @@ 
+/* { dg-options "-O0" } */
+
+extern void fn1 (void);
+
+int a;
+
+int
+main ()
+{
+  fn1 ();
+
+  if (a != 0) 
+    __builtin_abort (); 
+
+  return 0;
+}
Index: gcc/testsuite/gcc.dg/lto/pr64685_0.c
===================================================================
--- gcc/testsuite/gcc.dg/lto/pr64685_0.c	(revision 0)
+++ gcc/testsuite/gcc.dg/lto/pr64685_0.c	(working copy)
@@ -0,0 +1,10 @@ 
+/* { dg-lto-do run } */
+/* { dg-lto-options { { -flto } } } */
+
+extern int b;
+
+void
+fn1 (void)
+{
+    b = 0;
+}
Index: gcc/testsuite/gcc.dg/lto/pr64685_1.c
===================================================================
--- gcc/testsuite/gcc.dg/lto/pr64685_1.c	(revision 0)
+++ gcc/testsuite/gcc.dg/lto/pr64685_1.c	(working copy)
@@ -0,0 +1,27 @@ 
+/* { dg-options "-O1" } */
+
+extern void fn1 (void); 
+
+int a[2], b;
+
+static void
+foo (int p)
+{
+  b = 1 ^ a[(b ^ 1) & 1];
+  b = 1 ^ a[b & 1];
+  if (p)
+    __builtin_abort ();
+}
+
+int
+main ()
+{
+  foo (0);
+  b = 0;
+  foo (0);
+
+  if (b != 1)
+    __builtin_abort ();
+
+  return 0;
+}