This is the mail archive of the gcc@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]
Other format: [Raw text]

Re: g++ and aliasing bools



> An incremental improvement would be to allow at least C-type structs.
>
> {
>   if (AGGREGATE_TYPE_P (t) &&
>      IS_A_CLASS_DERIVED_FROM_ANOTHER_CLASS_P (t)) /* [1] */
>     return 0;
>
>   return c_common_get_alias_set (t);
> }
>
> should be safe because:
> a) the predicate [1] is true for any aggregate that is not a C-type struct
> b) c_common_get_alias_set deals with C-type structs correctly
> c) C-type structs cannot alias derived classes because the later are
>    put in alias set 0 because of [1]
>

See this is where things get subtle.  You have to (at least) worry
about whether or not t is zero-sized or has zero-sized bases or members.
If it does, there may be other zero-sized things at the same address.
If that's so, then if you put the zero-sized things in different alias
sets, you're saying they never alias.  Now, obviously, we never read or
write zero-sized things -- but different alias sets also implies that
&x != &y which is false.

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


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