Re: More fun with aliasing - removing assignments?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Harald van Dijk <truedfx@xxxxxxxxxx> writes:

> I finally managed to track down the problem I've been having to this
> short code:
> 
> 	typedef struct {
> 	    unsigned car;
> 	    unsigned cdr;
> 	} cons;
> 
> 	void nconc (unsigned x, unsigned y) {
> 	    unsigned *ptr = &x;
> 	    while(!(*ptr & 3))
> 	        ptr = &((cons *)(*ptr))->cdr;
> 	    *ptr = y;
> 	}
> 
> With gcc 4.0-20050728 on i686-pc-linux-gnu, compiling this with -O2
> appears to remove the assignment to *ptr. (I didn't prepare an example
> program, but it's verifiable with objdump.) Obviously, this code is
> non-portable, but still, I don't see why this can happen. Would anyone
> be kind enough to explain this to me? It works as expected with -O2
> -fno-strict-aliasing.

Well, I'd say it's a bug.  It works in 4.1.  The final assignment gets
removed by tree-ssa-dce.c because it looks like a useless store.  This
is because alias analysis thinks it knows what is going on, when it
clearly does not.

This patch happens to fix it in 4.0.  I doubt this is the right
approach, though.  It's a big hammer, which says that if you set a
pointer to the address of something, and you're not sure what that
thing is, then you have no idea what the pointer points to.

This code is completely different in 4.1.  In 4.1 the function
find_what_p_points_to is called, and it determines that it has no idea
what 'ptr' points to.

I think this should probably be fixed for 4.0.2, but I don't know if
this is the right patch at all.  It should at least be safe.

Ian

Index: tree-ssa-alias.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-alias.c,v
retrieving revision 2.71.2.2
diff -p -u -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 05:07:41 -0000
@@ -1901,6 +1901,8 @@ add_pointed_to_var (struct alias_info *a
       if (is_global_var (pt_var))
 	pi->pt_global_mem = 1;
     }
+  else
+    set_pt_anything (ptr);
 }
 
 


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux