]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/42898 (volatile structures and compound literal initializers)
authorRichard Guenther <rguenther@suse.de>
Sun, 31 Jan 2010 17:07:16 +0000 (17:07 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Sun, 31 Jan 2010 17:07:16 +0000 (17:07 +0000)
2010-01-31  Richard Guenther  <rguenther@suse.de>

PR middle-end/42898
* gimplify.c (gimplify_init_constructor): For volatile LHS
initialize a temporary.

* gcc.dg/torture/pr42898.c: New testcase.

From-SVN: r156407

gcc/ChangeLog
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr42898.c [new file with mode: 0644]

index 46692cb2fc17a0a541c7ada5e1b39257e82c356d..e05c1fd7c699be681202cb11506f7c9cd79ff9e1 100644 (file)
@@ -1,3 +1,9 @@
+2010-01-31  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/42898
+       * gimplify.c (gimplify_init_constructor): For volatile LHS
+       initialize a temporary.
+
 2010-01-26  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
 
        * config/sparc/sparc.c (sparc_elf_asm_named_section): Test for
index 2bf213c24e7b6bf5ceae9667bcb39174bf40603f..71af972b2659938a4b6ad0315d0d4f3583241a28 100644 (file)
@@ -3314,6 +3314,21 @@ gimplify_init_constructor (tree *expr_p, tree *pre_p,
              }
          }
 
+       /* If the target is volatile and we have non-zero elements
+          initialize the target from a temporary.  */
+       if (TREE_THIS_VOLATILE (object)
+           && !TREE_ADDRESSABLE (type)
+           && num_nonzero_elements > 0)
+         {
+           tree temp = create_tmp_var (TYPE_MAIN_VARIANT (type), NULL);
+           TREE_OPERAND (*expr_p, 0) = temp;
+           *expr_p = build2 (COMPOUND_EXPR, TREE_TYPE (*expr_p),
+                             *expr_p,
+                             build2 (MODIFY_EXPR, void_type_node,
+                                     object, temp));
+           return GS_OK;
+         }
+
        if (notify_temp_creation)
          return GS_OK;
 
index 8d02df2df5e4811e802ce84ef198705e3eaea998..0cef5d6f58615cc50a858f49f1e619d9c46ffddb 100644 (file)
@@ -1,3 +1,8 @@
+2010-01-31  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/42898
+       * gcc.dg/torture/pr42898.c: New testcase.
+
 2010-01-18  Uros Bizjak  <ubizjak@gmail.com>
 
        PR target/42774
diff --git a/gcc/testsuite/gcc.dg/torture/pr42898.c b/gcc/testsuite/gcc.dg/torture/pr42898.c
new file mode 100644 (file)
index 0000000..df8b46a
--- /dev/null
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-optimized" } */
+
+struct hardware {
+  int parm1:8;
+  int :4;
+  int parm2:4;
+  int parm3:15;
+  int parm4:1;
+};
+
+void f1(volatile struct hardware *ptr)
+{
+  *ptr=(struct hardware) {
+    .parm1=42,
+    .parm2=13,
+    .parm3=11850,
+    .parm4=1,
+  };
+}
+
+/* { dg-final { scan-tree-dump-times "\\*ptr" 1 "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */