diff options
author | Jakub Jelinek <jakub@redhat.com> | 2002-02-22 21:09:09 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2002-02-22 21:09:09 +0000 |
commit | ae8f70f537005a57b3f8c3ac691e8d0514de1e02 (patch) | |
tree | a72c0063813e38c6c4dd851832a48761e804370e | |
parent | 30f04595a1e8dff0755d47b4cb5046a39903528f (diff) |
PR c++/5748
* stmt.c (expand_anon_union_decl): Set TREE_USED on the anon union
decl if any of elements was TREE_USED.
* g++.dg/opt/anonunion1.C: New test.
git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@49971 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/stmt.c | 5 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/opt/anonunion1.C | 25 |
4 files changed, 40 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b4afe048bcb..252af066e80 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2002-02-22 Jakub Jelinek <jakub@redhat.com> + + PR c++/5748 + * stmt.c (expand_anon_union_decl): Set TREE_USED on the anon union + decl if any of elements was TREE_USED. + 2002-02-22 Alexandre Oliva <aoliva@redhat.com> * config/sparc/sol2.h: Don't include sys/mman.h. diff --git a/gcc/stmt.c b/gcc/stmt.c index fc968bcbab3..b41b62bb8d0 100644 --- a/gcc/stmt.c +++ b/gcc/stmt.c @@ -4201,6 +4201,11 @@ expand_anon_union_decl (decl, cleanup, decl_elts) tree cleanup_elt = TREE_PURPOSE (t); enum machine_mode mode = TYPE_MODE (TREE_TYPE (decl_elt)); + /* If any of the elements are addressable, so is the entire + union. */ + if (TREE_USED (decl_elt)) + TREE_USED (decl) = 1; + /* Propagate the union's alignment to the elements. */ DECL_ALIGN (decl_elt) = DECL_ALIGN (decl); DECL_USER_ALIGN (decl_elt) = DECL_USER_ALIGN (decl); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6785c5333df..e7149dd6a2c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2002-02-22 Jakub Jelinek <jakub@redhat.com> + + * g++.dg/opt/anonunion1.C: New test. + 2002-02-22 Nathan Sidwell <nathan@codesourcery.com> * g++.dg/template/qualttp19.C: New test. diff --git a/gcc/testsuite/g++.dg/opt/anonunion1.C b/gcc/testsuite/g++.dg/opt/anonunion1.C new file mode 100644 index 00000000000..445ebaa7cb1 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/anonunion1.C @@ -0,0 +1,25 @@ +// PR c++/5748 +// This testcase ICEd because used flag from the anon union variables +// was not propagated back to the anon union itself, causing addressof +// not to be replaced with stack slot. +// { dg-do compile } +// { dg-options "-O2" } + +struct A { + A (); + ~A (); + int foo (); + int bar (void *x, int y); +}; + +int A::foo() +{ + union { + int a; + int b; + }; + + if (bar (&a, sizeof (int)) != 32) + return 16; + return 0; +} |