[PATCH] Fix some IPA-PTA bugs

Richard Guenther rguenther@suse.de
Tue Apr 20 12:43:00 GMT 2010


This fixes mis-handling of structure copies with DEREF.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2010-04-20  Richard Guenther  <rguenther@suse.de>

	* tree-ssa-structalias.c (do_structure_copy): Properly handle
	DEREF.
	(dump_sa_points_to_info): Remove asserts.
	(init_base_vars): nothing_id isn't an escape point nor does it
	have pointers.

	* gcc.dg/ipa/ipa-pta-14.c: New testcase.

Index: gcc/tree-ssa-structalias.c
===================================================================
*** gcc/tree-ssa-structalias.c.orig	2010-04-20 14:33:41.000000000 +0200
--- gcc/tree-ssa-structalias.c	2010-04-20 14:34:17.000000000 +0200
*************** do_structure_copy (tree lhsop, tree rhso
*** 3403,3409 ****
    if (lhsp->type == DEREF
        || (lhsp->type == ADDRESSOF && lhsp->var == anything_id)
        || rhsp->type == DEREF)
!     process_all_all_constraints (lhsc, rhsc);
    else if (lhsp->type == SCALAR
  	   && (rhsp->type == SCALAR
  	       || rhsp->type == ADDRESSOF))
--- 3403,3421 ----
    if (lhsp->type == DEREF
        || (lhsp->type == ADDRESSOF && lhsp->var == anything_id)
        || rhsp->type == DEREF)
!     {
!       if (lhsp->type == DEREF)
! 	{
! 	  gcc_assert (VEC_length (ce_s, lhsc) == 1);
! 	  lhsp->offset = UNKNOWN_OFFSET;
! 	}
!       if (rhsp->type == DEREF)
! 	{
! 	  gcc_assert (VEC_length (ce_s, rhsc) == 1);
! 	  rhsp->offset = UNKNOWN_OFFSET;
! 	}
!       process_all_all_constraints (lhsc, rhsc);
!     }
    else if (lhsp->type == SCALAR
  	   && (rhsp->type == SCALAR
  	       || rhsp->type == ADDRESSOF))
*************** dump_sa_points_to_info (FILE *outfile)
*** 5910,5922 ****
      {
        varinfo_t vi = get_varinfo (i);
        if (!vi->may_have_pointers)
! 	{
! 	  gcc_assert (find (i) == i
! 		      || !(vi = get_varinfo (find (i)))->may_have_pointers);
! 	  /* ???  See create_variable_info_for.
! 	     gcc_assert (bitmap_empty_p (vi->solution));  */
! 	  continue;
! 	}
        dump_solution_for_var (outfile, i);
      }
  }
--- 5922,5928 ----
      {
        varinfo_t vi = get_varinfo (i);
        if (!vi->may_have_pointers)
! 	continue;
        dump_solution_for_var (outfile, i);
      }
  }
*************** init_base_vars (void)
*** 5955,5960 ****
--- 5961,5968 ----
    var_nothing->size = ~0;
    var_nothing->fullsize = ~0;
    var_nothing->is_special_var = 1;
+   var_nothing->may_have_pointers = 0;
+   var_nothing->is_global_var = 0;
  
    /* Create the ANYTHING variable, used to represent that a variable
       points to some unknown piece of memory.  */
Index: gcc/testsuite/gcc.dg/ipa/ipa-pta-14.c
===================================================================
*** /dev/null	1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/ipa/ipa-pta-14.c	2010-04-20 14:35:16.000000000 +0200
***************
*** 0 ****
--- 1,32 ----
+ /* { dg-do run } */
+ /* { dg-options "-O2 -fipa-pta -fno-tree-sra -fdump-ipa-pta-details" } */
+ 
+ struct X {
+     int i;
+     void *p;
+ };
+ 
+ static void * __attribute__((noinline,noclone))
+ foo(struct X *q, void *p)
+ {
+   struct X b;
+   b.p = p;
+   *q = b;
+   return q->p;
+ }
+ extern void abort (void);
+ int main()
+ {
+   struct X a, c;
+   void *p;
+   a.p = (void *)&c;
+   p = foo(&a, &a);
+   /* { dg-final { scan-ipa-dump "foo.result = { NULL a c }" "pta" { xfail *-*-* } } } */
+   /* { dg-final { scan-ipa-dump "foo.result = { NULL a a\[^ \]* c }" "pta" } } */
+   ((struct X *)p)->p = (void *)0;
+   if (a.p != (void *)0)
+     abort ();
+   return 0;
+ }
+ 
+ /* { dg-final { cleanup-ipa-dump "pta" } } */



More information about the Gcc-patches mailing list