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]

[PATCH]: Record aliases properly for C++ classes



This way, we can stop putting them all in the same alias set.

I just went by the reason the comments said we didn't do it, so can
someone "in the know" make sure  things haven't changed these days,
making my patch wrong? 


2001-07-13  Daniel Berlin  <dan@cgsoftware.com>

	* c-common.c (record_class_aliases): New function. Record alias
	sets for components of classes.
	(lang_get_alias_set): Use record_class_aliases for C++ classes.
Index: c-common.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-common.c,v
retrieving revision 1.242
diff -c -3 -p -w -B -b -r1.242 c-common.c
*** c-common.c	2001/07/10 06:18:32	1.242
--- c-common.c	2001/07/14 05:20:17
*************** c_apply_type_quals_to_decl (type_quals, 
*** 2754,2761 ****
--- 2754,2799 ----
  	}
      }
  }
+ static HOST_WIDE_INT record_class_aliases PARAMS ((tree));
+ /* For C++ classes, record the aliases of this class's fields as a
+    subset of this classes alias set, and then recursively do so for the
+    base classes, making sure to mark the alias set of the baseclass as a
+    subset of us */
+ static HOST_WIDE_INT 
+ record_class_aliases (t)
+      tree t;
+ {
+   int i;
+   HOST_WIDE_INT set;
+   tree binfo, field;
+   /* If we already know the alias set, return it. */
+   if (TYPE_ALIAS_SET_KNOWN_P (t))
+       return TYPE_ALIAS_SET (t);
+   /* Otherwise, make a new set. */
+   else 
+     {
+       set = new_alias_set ();
+       TYPE_ALIAS_SET (t) = set;
+     }
+   /* Record aliases for the fields */
  
+   for (field = TYPE_FIELDS (t); field != 0; field = TREE_CHAIN (field))
+     if (TREE_CODE (field) == FIELD_DECL && !DECL_NONADDRESSABLE_P (field))
+       record_alias_subset (set, get_alias_set (TREE_TYPE (field)));
  
+   /* Recursively record aliases for the base classes, if there are any */
+   if (TYPE_BINFO_BASETYPES (t) != NULL)
+     {
+       for (i = 0; i < TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (t)); i++)
+ 	{
+ 	  binfo = TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), i);
+ 	  /* The baseclass alias set is a subset of our alias class */
+ 	  record_alias_subset (set, record_class_aliases (BINFO_TYPE (binfo)));
+ 	}
+     }
+   return set;
+ }
+ 
  /* Return the typed-based alias set for T, which may be an expression
     or a type.  Return -1 if we don't do anything special.  */
  
*************** lang_get_alias_set (t)
*** 2837,2847 ****
      }
!   /* It's not yet safe to use alias sets for classes in C++ because
!      the TYPE_FIELDs list for a class doesn't mention base classes.  */
!   else if (c_language == clk_cplusplus && AGGREGATE_TYPE_P (t))
!     return 0;
! 
    return -1;
  }
  
  /* Build tree nodes and builtin functions common to both C and C++ language
     frontends.  */
--- 2875,2888 ----
      }
!   /* Work around the fact that the TYPE_FIELDs list for a class
!      doesn't mention base classes. */
!   else if (c_language == clk_cplusplus && AGGREGATE_TYPE_P (t) 
! 	   && TYPE_BINFO (t) != NULL)
!     {
!       return record_class_aliases (t);
!     }
    return -1;
  }
+ 
  
  /* Build tree nodes and builtin functions common to both C and C++ language
     frontends.  */


-- 
"I have the world's largest collection of seashells.  I keep it
on all the beaches of the world...  Perhaps you've seen it.
"-Steven Wright


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