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]

[PATCH]: Fix PR tree-optimization/24117


In cases like

x = (char *)&x

the points-to analyzer missed adding ANYOFFSET because it didn't strip
the cast to see that all of x escaped.

Fixed by stripping the case before checking whether we need ANYOFFSET.

Thanks to richard guenther for producing such a nice small testcase :)


Bootstrapped and regtested on i686-pc-linux-gnu

Applied to mainline.
--Dan

2005-09-29  Daniel Berlin  <dberlin@dberlin.org>
	
	Fix PR tree-optimization/24117
	* tree-ssa-structalias.c (find_func_aliases): Strip nops
	before considering whether to use anyoffset.
Index: tree-ssa-structalias.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-structalias.c,v
retrieving revision 2.29
diff -u -p -r2.29 tree-ssa-structalias.c
--- tree-ssa-structalias.c	22 Sep 2005 00:42:28 -0000	2.29
+++ tree-ssa-structalias.c	29 Sep 2005 17:26:27 -0000
@@ -2817,16 +2817,18 @@ find_func_aliases (tree t, struct alias_
 		  case tcc_expression:
 		  case tcc_unary:
 		      {
+			tree anyoffsetrhs = rhsop;
 			bool need_anyoffset = false;
 			rhs = get_constraint_for (rhsop, &need_anyoffset);
 			process_constraint (new_constraint (lhs, rhs));
-
+			
+			STRIP_NOPS (anyoffsetrhs);
 			/* When taking the address of an aggregate
 			   type, from the LHS we can access any field
 			   of the RHS.  */
 			if (need_anyoffset || (rhs.type == ADDRESSOF
 			    && !(get_varinfo (rhs.var)->is_special_var)
-			    && AGGREGATE_TYPE_P (TREE_TYPE (TREE_TYPE (rhsop)))))
+			    && AGGREGATE_TYPE_P (TREE_TYPE (TREE_TYPE (anyoffsetrhs)))))
 			  {
 			    rhs.var = anyoffset_id;
 			    rhs.type = ADDRESSOF;
Index: testsuite/gcc.dg/tree-ssa/pr24117.c
===================================================================
RCS file: testsuite/gcc.dg/tree-ssa/pr24117.c
diff -N testsuite/gcc.dg/tree-ssa/pr24117.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.dg/tree-ssa/pr24117.c	29 Sep 2005 17:26:31 -0000
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+typedef struct  {
+  int x;
+  int z;
+} Foo_t;
+
+char *xm;
+void bar(void);
+
+void foo(void)
+{
+  Foo_t x;
+  x.x = 1;
+  x.z = 2;
+  xm = (char *)&x;
+  bar();
+  /* We can't propagate x.z past bar, so this link_error should still be there.  */
+  if (x.z != 2)
+    link_error ();
+}
+/* { dg-final { scan-tree-dump-times "link_error" 1 "optimized"} } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */

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