This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: RFC: g++ aliasing (was: Re: g++ and aliasing bools)
Mark Mitchell <mark@codesourcery.com> writes:
> > + else
> > + /* This should never happen, we dealt with all the aggregate
> > + types that can appear in C++ abover. */
>
> "above", not "abover"
>
> Also, I would add -- at the very beginning, even before AGGREGATE_TYPE_P.
>
> if (TYPE_PTRMEMFUNC_P (t))
> return true;
>
> Technically, you don't need to this -- pointers-to-member functions are
> represented as RECORD_TYPEs. But, I think it would make things clearer.
OK.
> Let's try making this change for 3.2 and see what happens.
>
> I, too, am nervous about the vtable issue, but we'll hope for the best.
>
> Patch approved for mainline, with the two minor changes suggested
> above.
I don't have write access, so could you please check in the patch?
The updated version is below.
2002-03-06 Dan Nicolaescu <dann@ics.uci.edu>
Daniel Berlin <dan@dberlin.org>
C++ alias analysis improvement.
* alias.c (record_component_aliases): Record aliases for base
classes too.
* cp/cp-lang.c (ok_to_generate_alias_set_for_type): New function.
(cxx_get_alias_set): Use it.
*** alias.c.~1.166.~ Tue Mar 5 23:56:32 2002
--- alias.c Tue Mar 5 23:57:14 2002
***************
*** 679,684 ****
--- 679,694 ----
case RECORD_TYPE:
case UNION_TYPE:
case QUAL_UNION_TYPE:
+ /* Recursively record aliases for the base classes, if there are any */
+ if (TYPE_BINFO (type) != NULL && TYPE_BINFO_BASETYPES (type) != NULL)
+ {
+ int i;
+ for (i = 0; i < TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type)); i++)
+ {
+ tree binfo = TREE_VEC_ELT (TYPE_BINFO_BASETYPES (type), i);
+ record_alias_subset (superset, get_alias_set (BINFO_TYPE (binfo)));
+ }
+ }
for (field = TYPE_FIELDS (type); field != 0; field = TREE_CHAIN (field))
if (TREE_CODE (field) == FIELD_DECL && ! DECL_NONADDRESSABLE_P (field))
record_alias_subset (superset, get_alias_set (TREE_TYPE (field)));
Index: cp-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-lang.c,v
retrieving revision 1.10
diff -c -3 -p -c -r1.10 cp-lang.c
*** cp-lang.c 2002/02/28 07:39:37 1.10
--- cp-lang.c 2002/03/07 06:54:41
*************** static HOST_WIDE_INT cxx_get_alias_set P
*** 97,112 ****
/* Each front end provides its own hooks, for toplev.c. */
const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
/* Special routine to get the alias set for C++. */
static HOST_WIDE_INT
cxx_get_alias_set (t)
tree t;
{
! /* 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. */
! if (AGGREGATE_TYPE_P (t))
return 0;
!
return c_common_get_alias_set (t);
}
--- 97,207 ----
/* Each front end provides its own hooks, for toplev.c. */
const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
+ /* Check if a C++ type is safe for aliasing.
+ Return TRUE if T safe for aliasing FALSE otherwise. */
+
+ static bool
+ ok_to_generate_alias_set_for_type (t)
+ tree t;
+ {
+ if (TYPE_PTRMEMFUNC_P (t))
+ return true;
+ if (AGGREGATE_TYPE_P (t))
+ {
+ if ((TREE_CODE (t) == RECORD_TYPE) || (TREE_CODE (t) == UNION_TYPE))
+ {
+ tree fields;
+ /* PODs are safe. */
+ if (! CLASSTYPE_NON_POD_P(t))
+ return true;
+ /* Classes with virtual baseclasses are not. */
+ if (TYPE_USES_VIRTUAL_BASECLASSES (t))
+ return false;
+ /* Recursively check the base classes. */
+ if (TYPE_BINFO (t) != NULL && TYPE_BINFO_BASETYPES (t) != NULL)
+ {
+ int i;
+ for (i = 0; i < TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (t)); i++)
+ {
+ tree binfo = TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), i);
+ if (!ok_to_generate_alias_set_for_type (BINFO_TYPE (binfo)))
+ return false;
+ }
+ }
+ /* Check all the fields. */
+ for (fields = TYPE_FIELDS (t); fields; fields = TREE_CHAIN (fields))
+ {
+ if (TREE_CODE (fields) != FIELD_DECL)
+ continue;
+ if (! ok_to_generate_alias_set_for_type (TREE_TYPE (fields)))
+ return false;
+ }
+ return true;
+ }
+ else if (TREE_CODE (t) == ARRAY_TYPE)
+ return ok_to_generate_alias_set_for_type (TREE_TYPE (t));
+ else
+ /* This should never happen, we dealt with all the aggregate
+ types that can appear in C++ above. */
+ abort ();
+ }
+ else
+ return true;
+ }
+
/* Special routine to get the alias set for C++. */
static HOST_WIDE_INT
cxx_get_alias_set (t)
tree t;
{
! /* It's not yet safe to use alias sets for some classes in C++ */
! if (!ok_to_generate_alias_set_for_type(t))
return 0;
!
return c_common_get_alias_set (t);
}