Fix PR 23192

Diego Novillo dnovillo@redhat.com
Tue Aug 2 14:00:00 GMT 2005


We were not computing points-to information correctly when the
code takes the address of anything other than a VAR_DECL.

	PR 23192
	* tree-ssa-alias.c (add_pointed_to_var): If VALUE is of the
	form &(*PTR), take points-to information from PTR.
	Give up if VALUE by marking PTR as pointing anywhere if VALUE
	is not recognized.

testsuite/ChangeLog

	PR 23192
	* gcc.dg/pr23192.c: New test.

Index: tree-ssa-alias.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-alias.c,v
retrieving revision 2.71.2.2
diff -d -u -p -r2.71.2.2 tree-ssa-alias.c
--- tree-ssa-alias.c	26 Jul 2005 20:54:21 -0000	2.71.2.2
+++ tree-ssa-alias.c	2 Aug 2005 12:55:25 -0000
@@ -1887,7 +1887,11 @@ add_pointed_to_var (struct alias_info *a
   if (REFERENCE_CLASS_P (pt_var))
     pt_var = get_base_address (pt_var);
 
-  if (pt_var && SSA_VAR_P (pt_var))
+  if (pt_var == NULL)
+    {
+      pi->pt_anything = 1;
+    }
+  else if (SSA_VAR_P (pt_var))
     {
       uid = var_ann (pt_var)->uid;
       bitmap_set_bit (ai->addresses_needed, uid);
@@ -1901,6 +1905,18 @@ add_pointed_to_var (struct alias_info *a
       if (is_global_var (pt_var))
 	pi->pt_global_mem = 1;
     }
+  else if (TREE_CODE (pt_var) == INDIRECT_REF
+           && TREE_CODE (TREE_OPERAND (pt_var, 0)) == SSA_NAME)
+    {
+      /* If VALUE is of the form &(*P_j), then PTR will have the same
+	 points-to information as P_j.  */
+      add_pointed_to_expr (ai, ptr, TREE_OPERAND (pt_var, 0));
+    }
+  else
+    {
+      /* Give up.  PTR points anywhere.  */
+      set_pt_anything (ptr);
+    }
 }
 
 
Index: testsuite/gcc.dg/tree-ssa/pr23192.c
===================================================================
RCS file: testsuite/gcc.dg/tree-ssa/pr23192.c
diff -N testsuite/gcc.dg/tree-ssa/pr23192.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.dg/tree-ssa/pr23192.c	2 Aug 2005 12:55:27 -0000
@@ -0,0 +1,23 @@
+/* { dg-options "-O2" } */
+/* { dg-do run } */
+
+struct S { int i; } s;
+
+void f (struct S *q)
+{
+  int a, *p;
+  p = &a;
+  if (q)
+    p = &q->i;
+  *p = 1;
+}
+
+void abort (void);
+
+int main (void)
+{
+  f (&s);
+  if (s.i != 1)
+    abort ();
+  return 0;
+}



More information about the Gcc-patches mailing list