This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix PR38826 and PR38477


On Wed, 14 Jan 2009, Richard Guenther wrote:

> On Tue, 13 Jan 2009, Daniel Berlin wrote:
> 
> > How is this not going to become the same problem with IPA mode?
> > ISTM we should probably move the computation of call clobbering to be
> > more independent of the rest of PTA.
> 
> You cannot decouple them, as a call may clobber (and thus affects
> the points-to sets) of all reachable memory.  Unless you mark all
> memory that had its address taken as pointing to anything after each call,
> of course.

And of course it also affects IPA mode.
 
> > So, after talking with some others who work on points-to algorithms,
> > we've all agreed the proper solution to this problem is to mark all
> > nodes in a structure as indirect when the structure is address taken
> > (IE set graph->direct_nodes[n] false for each node). The notion of an
> > indirect node is that it can be referenced without using it's
> > syntactic name, which is exactly what is happening here.
> > This only affects the offline optimization portion.
> > It will cause slightly less offline optimization, but that is fixable
> > in other ways.
> 
> Ok, I will try to do this.
> 
> > If you'd like to disable field-sensitivity, i'd rather see us do that
> > as a separate patch, since the bug you are fixing would still remain
> > if you go this route.
> > :)
> 
> Agreed.

Here is what I came up with.  The testcases are fixed.

Bootstrapped and tested on x86_64-unknown-linux-gnu, ok for trunk?

Thanks,
Richard.

2009-01-14  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/38826
	PR middle-end/38477
	* tree-ssa-structalias.c (emit_alias_warning): Emit the pointer
	initialization notes only if we actually emitted a warning.
	(intra_create_variable_infos): Add constraints for a result decl
	that is passed by hidden reference.
	(build_pred_graph): Mark all related variables non-direct on
	address-taking.

	* gcc.dg/Wstrict-aliasing-bogus-pta-1.c: New testcase.

Index: gcc/testsuite/gcc.dg/Wstrict-aliasing-bogus-pta-1.c
===================================================================
*** /dev/null	1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/Wstrict-aliasing-bogus-pta-1.c	2009-01-14 14:02:25.000000000 +0100
***************
*** 0 ****
--- 1,19 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O2 -Wall" } */
+ 
+ struct S { int *p; int *q; };
+ 
+ void foo (struct S *);
+ 
+ int bar (int b)
+ {
+   struct S s;
+   int *p;
+   float f;
+   foo (&s);
+   if (b)
+     p = s.q;
+   else
+     p = (int *)&f;
+   return *p;
+ }
Index: gcc/tree-ssa-structalias.c
===================================================================
*** gcc/tree-ssa-structalias.c.orig	2009-01-14 14:02:05.000000000 +0100
--- gcc/tree-ssa-structalias.c	2009-01-14 14:07:52.000000000 +0100
*************** build_pred_graph (void)
*** 1129,1134 ****
--- 1129,1136 ----
  	}
        else if (rhs.type == ADDRESSOF)
  	{
+ 	  varinfo_t v;
+ 
  	  /* x = &y */
  	  if (graph->points_to[lhsvar] == NULL)
  	    graph->points_to[lhsvar] = BITMAP_ALLOC (&predbitmap_obstack);
*************** build_pred_graph (void)
*** 1141,1147 ****
--- 1143,1161 ----
  	  /* Implicitly, *x = y */
  	  add_implicit_graph_edge (graph, FIRST_REF_NODE + lhsvar, rhsvar);
  
+ 	  /* All related variables are no longer direct nodes.  */
  	  RESET_BIT (graph->direct_nodes, rhsvar);
+ 	  v = get_varinfo (rhsvar);
+ 	  if (!v->is_full_var)
+ 	    {
+ 	      v = lookup_vi_for_tree (v->decl);
+ 	      do
+ 		{
+ 		  RESET_BIT (graph->direct_nodes, v->id);
+ 		  v = v->next;
+ 		}
+ 	      while (v != NULL);
+ 	    }
  	  bitmap_set_bit (graph->address_taken, rhsvar);
  	}
        else if (lhsvar > anything_id
*************** intra_create_variable_infos (void)
*** 4561,4566 ****
--- 4575,4590 ----
  	}
      }
  
+   /* Add a constraint for a result decl that is passed by reference.  */
+   if (DECL_RESULT (cfun->decl)
+       && DECL_BY_REFERENCE (DECL_RESULT (cfun->decl)))
+     {
+       varinfo_t p, result_vi = get_vi_for_tree (DECL_RESULT (cfun->decl));
+ 
+       for (p = result_vi; p; p = p->next)
+         make_constraint_from (p, nonlocal_id);
+     }
+ 
    /* Add a constraint for the incoming static chain parameter.  */
    if (cfun->static_chain_decl != NULL_TREE)
      {
*************** emit_alias_warning (tree ptr)
*** 4735,4741 ****
  {
    gimple use;
    imm_use_iterator ui;
!   unsigned warned = 0;
  
    FOR_EACH_IMM_USE_STMT (use, ui, ptr)
      {
--- 4759,4765 ----
  {
    gimple use;
    imm_use_iterator ui;
!   bool warned = false;
  
    FOR_EACH_IMM_USE_STMT (use, ui, ptr)
      {
*************** emit_alias_warning (tree ptr)
*** 4773,4785 ****
  	  && !TREE_NO_WARNING (deref))
  	{
  	  TREE_NO_WARNING (deref) = 1;
! 	  warning_at (gimple_location (use), OPT_Wstrict_aliasing,
! 		      "dereferencing pointer %qD does break strict-aliasing "
! 		      "rules", SSA_NAME_VAR (ptr));
! 	  ++warned;
  	}
      }
!   if (warned > 0)
      {
        bitmap visited = BITMAP_ALLOC (NULL);
        emit_pointer_definition (ptr, visited);
--- 4797,4808 ----
  	  && !TREE_NO_WARNING (deref))
  	{
  	  TREE_NO_WARNING (deref) = 1;
! 	  warned |= warning_at (gimple_location (use), OPT_Wstrict_aliasing,
! 				"dereferencing pointer %qD does break "
! 				"strict-aliasing rules", SSA_NAME_VAR (ptr));
  	}
      }
!   if (warned)
      {
        bitmap visited = BITMAP_ALLOC (NULL);
        emit_pointer_definition (ptr, visited);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]