This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH to get_alias_set
- To: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Subject: PATCH to get_alias_set
- From: Jason Merrill <jason_merrill at redhat dot com>
- Date: 07 Aug 2001 12:05:34 +0100
The C++ anonymous union object feature is currently implemented by creating
new VAR_DECLs for each member of the union and giving them all the same
RTL. This confuses the alias optimizer, which looks at the types of these
decls and decides that they cannot alias one another. But the RTL already
has the correct alias set information, so we can just use that. And we
might as well, anyway.
I think anonymous unions should eventually be reimplemented so that
references to the members are implicitly rewritten to COMPONENT_REFs. I'm
uncomfortable with anything that relies on RTL to express frontend
semantics.
2001-07-31 Jason Merrill <jason_merrill@redhat.com>
* alias.c (get_alias_set): Return a previously calculated
alias set for a VAR_DECL.
*** alias.c.~1~ Tue Aug 7 00:49:37 2001
--- alias.c Tue Aug 7 00:47:43 2001
*************** get_alias_set (t)
*** 527,532 ****
--- 527,539 ----
return 0;
}
+ /* If we've already determined the alias set for this decl, just
+ return it. This is necessary for C++ anonymous unions, whose
+ component variables don't look like union members (boo!). */
+ if (TREE_CODE (t) == VAR_DECL
+ && DECL_RTL_SET_P (t) && GET_CODE (DECL_RTL (t)) == MEM)
+ return MEM_ALIAS_SET (DECL_RTL (t));
+
/* Give the language another chance to do something special. */
if (orig_t != t
&& (set = lang_get_alias_set (t)) != -1)
// Test that type punning using an anonymous union works with strict aliasing.
// { dg-do run }
// { dg-options -O2 -fstrict-aliasing }
extern "C" void abort ();
void f (int i)
{
union
{
int ui;
float uf[2];
};
ui = i;
if (uf[0] != 42.0)
abort ();
}
int main ()
{
union U { int i; float f[2]; } u;
u.f[0] = 42.0;
f (u.i);
}