aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/alias.c7
-rw-r--r--gcc/testsuite/g++.dg/opt/alias1.C25
3 files changed, 37 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 7c66b67..760dd95 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2001-08-07 Jason Merrill <jason_merrill@redhat.com>
+
+ * alias.c (get_alias_set): Return a previously calculated
+ alias set for a VAR_DECL.
+
2001-08-06 Richard Henderson <rth@redhat.com>
* varasm.c (assemble_gc_entry): Remove.
diff --git a/gcc/alias.c b/gcc/alias.c
index e741718..a529a01 100644
--- a/gcc/alias.c
+++ b/gcc/alias.c
@@ -527,6 +527,13 @@ get_alias_set (t)
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)
diff --git a/gcc/testsuite/g++.dg/opt/alias1.C b/gcc/testsuite/g++.dg/opt/alias1.C
new file mode 100644
index 0000000..34aed59
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/alias1.C
@@ -0,0 +1,25 @@
+// 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);
+}