g++ and aliasing bools
Daniel Berlin
dan@dberlin.org
Fri Jan 25 15:43:00 GMT 2002
On Fri, 25 Jan 2002, Joe Buck wrote:
> I wrote:
>
> [ attempt at a proof that Daniel's right ]
>
> Mark writes:
> > Your proof has at least one bug. A type that has no baseclasses or
> > virtuals can contain (as a data member) a type that does; such a type
> > is at least as complex as the contained type. (Similarly, an array
> > of classes with virtual bases, etc.) You need to recurse through the
> > type structure.
>
> Good catch. OK, Daniel, Mark has demonstrated that he was correct in
> asking you for a proof: your proposal was wrong.
Not quite, Mark has caught a case that is already handled properly.
It is impossible for the type involved as a member to have been given an
alias set other than 0, by the same test. So we would never improperly
generate code because of it.
If you want to me to show both it, and the current type, would be placed
in set 0:
The C machinery in question records component aliases of structs.
In recording component aliases of structs, it recursively walks the
members, and gets alias sets for their types, recording them as subsets of
the struct's alias set:
>From record_component_aliases:
"
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)));
"
Once we hit the tree type of the field in question, we'll record it as
having alias set 0 (it will fail the test, or the same process above
will repeat, if it has a member that is itself too complex), and then
record our type as having alias set 0 as a subset.
That will cause record_alias_subset to mark the alias set as a child of
zero (there's a flag to do this), which is commented as:
"
/* Nonzero if would have a child of zero: this effectively makes
this
alias set the same as alias set zero. */
"
Thus, no accesses to the type in question will be treated as not aliasing
anything else.
--Dan
More information about the Gcc
mailing list