public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR91131
@ 2019-07-10 14:11 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2019-07-10 14:11 UTC (permalink / raw)
  To: gcc-patches


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  <rguenther@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 } } */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-07-10 14:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-10 14:11 [PATCH] Fix PR91131 Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).