aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2007-12-12 11:12:39 +0000
committerAldy Hernandez <aldyh@gcc.gnu.org>2007-12-12 11:12:39 +0000
commit4caa08daa39346095599fee9b4608381128fb48f (patch)
tree152c25d48afd460f70909cee7507677f1f8c0bfa
parentee3f344964c9f427c2d63438a627f8755b716e53 (diff)
downloadgcc-4caa08daa39346095599fee9b4608381128fb48f.zip
gcc-4caa08daa39346095599fee9b4608381128fb48f.tar.gz
gcc-4caa08daa39346095599fee9b4608381128fb48f.tar.bz2
gimplify.c (gimplify_modify_expr_rhs): Handle the case when we are assigning from a constant constructor.
* gimplify.c (gimplify_modify_expr_rhs): Handle the case when we are assigning from a constant constructor. Fix wrapping in function comment. From-SVN: r130788
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/gimplify.c17
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr32901.c24
3 files changed, 46 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index cab09cb..aa00c5d 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2007-12-12 Aldy Hernandez <aldyh@redhat.com>
+
+ PR tree-optimization/32901
+ * gimplify.c (gimplify_modify_expr_rhs): Handle the case when we
+ are assigning from a constant constructor.
+ Fix wrapping in function comment.
+
2007-12-12 Andreas Krebbel <krebbel1@de.ibm.com>
* config/s390/s390.c (s390_O_constraint_str): Limit the range
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 06f7380..54d5c46 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -3470,8 +3470,9 @@ fold_indirect_ref_rhs (tree t)
return NULL_TREE;
}
-/* Subroutine of gimplify_modify_expr to do simplifications of MODIFY_EXPRs
- based on the code of the RHS. We loop for as long as something changes. */
+/* Subroutine of gimplify_modify_expr to do simplifications of
+ MODIFY_EXPRs based on the code of the RHS. We loop for as long as
+ something changes. */
static enum gimplify_status
gimplify_modify_expr_rhs (tree *expr_p, tree *from_p, tree *to_p, tree *pre_p,
@@ -3482,6 +3483,18 @@ gimplify_modify_expr_rhs (tree *expr_p, tree *from_p, tree *to_p, tree *pre_p,
while (ret != GS_UNHANDLED)
switch (TREE_CODE (*from_p))
{
+ case VAR_DECL:
+ /* If we're assigning from a constant constructor, move the
+ constructor expression to the RHS of the MODIFY_EXPR. */
+ if (DECL_INITIAL (*from_p)
+ && TYPE_READONLY (TREE_TYPE (*from_p))
+ && TREE_CODE (DECL_INITIAL (*from_p)) == CONSTRUCTOR)
+ {
+ *from_p = DECL_INITIAL (*from_p);
+ ret = GS_OK;
+ }
+ ret = GS_UNHANDLED;
+ break;
case INDIRECT_REF:
{
/* If we have code like
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr32901.c b/gcc/testsuite/gcc.dg/tree-ssa/pr32901.c
new file mode 100644
index 0000000..9102a88
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr32901.c
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-gimple" } */
+
+struct foo {
+ unsigned a1: 1;
+ unsigned a2: 3;
+ unsigned : 4;
+};
+
+extern struct foo thefoo;
+
+void setup_foo(void)
+{
+ const struct foo init = {
+ .a1 = 1,
+ .a2 = 5,
+ };
+ thefoo = init;
+}
+
+/* { dg-final { scan-tree-dump-times "thefoo.0 = \{\}" 1 "gimple"} } */
+/* { dg-final { scan-tree-dump-times "thefoo.0.a1 = 1" 1 "gimple"} } */
+/* { dg-final { scan-tree-dump-times "thefoo.0.a2 = 5" 1 "gimple"} } */
+/* { dg-final { cleanup-tree-dump "gimple" } } */