This is the mail archive of the gcc-bugs@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]

Re: neat bug in alias analysis



Mike --

  Thanks for your patch.  It's a bit more conservative than would be
ideal, but it probably doesn't matter in practice.  I was getting hung
up on solving the ideal problem.  We can always come back to that
later.

  I added some clarifying comments, and checked in the attached
version, after bootstrap/check and verifying that it fixed your
test-case.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

Thu Aug 19 14:42:38 1999  Mike Stump <mrs@wrs.com>
	                  Mark Mitchell <mark@codesourcery.com>

	* c-common.c (c_get_alias_set): Fix support for poitners and
	references.

Index: c-common.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-common.c,v
retrieving revision 1.63
diff -c -p -r1.63 c-common.c
*** c-common.c	1999/07/31 01:13:07	1.63
--- c-common.c	1999/08/19 21:37:04
*************** c_get_alias_set (t)
*** 3401,3411 ****
         whose type is the same as one of the fields, recursively, but
         we don't yet make any use of that information.)  */
      TYPE_ALIAS_SET (type) = 0;
  
    if (!TYPE_ALIAS_SET_KNOWN_P (type)) 
!     /* TYPE is something we haven't seen before.  Put it in a new
!        alias set.  */
!     TYPE_ALIAS_SET (type) = new_alias_set ();
  
    return TYPE_ALIAS_SET (type);
  }
--- 3401,3441 ----
         whose type is the same as one of the fields, recursively, but
         we don't yet make any use of that information.)  */
      TYPE_ALIAS_SET (type) = 0;
+   else if (TREE_CODE (type) == POINTER_TYPE
+ 	   || TREE_CODE (type) == REFERENCE_TYPE)
+     {
+       tree t;
  
+       /* Unfortunately, there is no canonical form of a pointer type.
+ 	 In particular, if we have `typedef int I', then `int *', and
+ 	 `I *' are different types.  So, we have to pick a canonical
+ 	 representative.  We do this below.
+ 	 
+ 	 Note that this approach is actually more conservative that it
+ 	 needs to be.  In particular, `const int *' and `int *' should
+ 	 be in different alias sets, but this approach puts them in
+ 	 the same alias set.  */
+ 
+       t = TYPE_MAIN_VARIANT (TREE_TYPE (type));
+       t = ((TREE_CODE (type) == POINTER_TYPE)
+ 	   ? build_pointer_type (t) : build_reference_type (t));
+       if (t != type)
+ 	TYPE_ALIAS_SET (type) = c_get_alias_set (t);
+     }
+ 
    if (!TYPE_ALIAS_SET_KNOWN_P (type)) 
!     {
!       /* Types that are not allocated on the permanent obstack are not
! 	 placed in the type hash table.  Thus, there can be multiple
! 	 copies of identical types in local scopes.  In the long run,
! 	 all types should be permanent.  */
!       if (! TREE_PERMANENT (type))
! 	TYPE_ALIAS_SET (type) = 0;
!       else
! 	/* TYPE is something we haven't seen before.  Put it in a new
! 	   alias set.  */
! 	TYPE_ALIAS_SET (type) = new_alias_set ();
!     }
  
    return TYPE_ALIAS_SET (type);
  }


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