The PR complains that we fail to properly initialize a
volatile struct with a single assignment if the initializer
is all-zeros.

Fixed as follows.

Bootstrap / regtest running on x86_64-unknown-linux-gnu.

Richard.

2019-07-10  Richard Biener  <rguent...@suse.de>

        PR middle-end/91131
        * gimplify.c (gimplify_compound_literal_expr): Force a temporary
        when the object is volatile and we have not cleared it even though
        there are no nonzero elements.

        * gcc.target/i386/pr91131.c: New testcase.

Index: gcc/gimplify.c
===================================================================
--- gcc/gimplify.c      (revision 273355)
+++ gcc/gimplify.c      (working copy)
@@ -5005,7 +5004,7 @@ gimplify_init_constructor (tree *expr_p,
           one field to assign, initialize the target from a temporary.  */
        if (TREE_THIS_VOLATILE (object)
            && !TREE_ADDRESSABLE (type)
-           && num_nonzero_elements > 0
+           && (num_nonzero_elements > 0 || !cleared)
            && vec_safe_length (elts) > 1)
          {
            tree temp = create_tmp_var (TYPE_MAIN_VARIANT (type));
Index: gcc/testsuite/gcc.target/i386/pr91131.c
===================================================================
--- gcc/testsuite/gcc.target/i386/pr91131.c     (nonexistent)
+++ gcc/testsuite/gcc.target/i386/pr91131.c     (working copy)
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+struct Reg_T {
+    unsigned int a : 3;
+    unsigned int b : 1;
+    unsigned int c : 4;
+};
+
+volatile struct Reg_T Reg_A;
+
+int
+main ()
+{
+  Reg_A = (struct Reg_T){ .a = 0, .b = 0, .c = 0 };
+  return 0;
+}
+
+/* { dg-final { scan-assembler-times "mov\[^\r\n\]*Reg_A" 1 } } */

Reply via email to