From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 80676 invoked by alias); 10 Jul 2019 14:04:32 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 80668 invoked by uid 89); 10 Jul 2019 14:04:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,KAM_NUMSUBJECT,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 10 Jul 2019 14:04:21 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 4F34EAEAF for ; Wed, 10 Jul 2019 14:04:19 +0000 (UTC) Date: Wed, 10 Jul 2019 14:11:00 -0000 From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR91131 Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-SW-Source: 2019-07/txt/msg00807.txt.bz2 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 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 } } */