From patchwork Mon Aug 8 03:37:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 56591 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3B06A385736A for ; Mon, 8 Aug 2022 03:38:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B06A385736A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1659929890; bh=4erXbgJXzwgvze1n/3JOOUwSVL9ndW09OVmXIfYasKM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=kubDZnq+glTYk1ZaZDii8aRnvsgFPMKmkAH6fQwT9/0+9Y/kkkslgaCbSw7/9njlb Ss9HwivKDfcPeWGbFzeaMY0daPQZ7ycon79cmQV3OqLQVK4xzrHVR7aecZzv8sdXN3 Vn++av5PZBaJVxOozznACSLm6TVqBLX3U10DyhP8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 8A3D338582B3 for ; Mon, 8 Aug 2022 03:37:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8A3D338582B3 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 277MmMTv011992 for ; Sun, 7 Aug 2022 20:37:41 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3hsqtmm6fb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 07 Aug 2022 20:37:41 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 7 Aug 2022 20:37:39 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sun, 7 Aug 2022 20:37:38 -0700 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id CA0325B694D; Sun, 7 Aug 2022 20:37:32 -0700 (PDT) To: Subject: [PATCH] Fix middle-end/103645: empty struct store not removed when using compound literal Date: Sun, 7 Aug 2022 20:37:06 -0700 Message-ID: <1659929826-10136-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Proofpoint-GUID: fgF-8kUmbDD7EcfzxsvRDnM_V_VkoiNv X-Proofpoint-ORIG-GUID: fgF-8kUmbDD7EcfzxsvRDnM_V_VkoiNv X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-08_01,2022-08-05_01,2022-06-22_01 X-Spam-Status: No, score=-14.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: apinski--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: apinski@marvell.com Cc: Andrew Pinski Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Andrew Pinski For compound literals empty struct stores are not removed as they go down a different path of the gimplifier; trying to optimize the init constructor. This fixes the problem by not adding the gimple assignment at the end of gimplify_init_constructor if it was an empty type. Note this updates gcc.dg/pr87052.c where we had: const char d[0] = { }; And was expecting a store to d but after this, there is no store as the decl's type is zero in size. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: PR middle-end/103645 * gimplify.c (gimplify_init_constructor): Don't build/add gimple assignment of an empty type. testsuite/ChangeLog: * gcc.dg/pr87052.c: Update d var to expect nothing. --- gcc/gimplify.cc | 7 +++++-- gcc/testsuite/gcc.dg/pr87052.c | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 2ac7ca0855e..f0fbdb48012 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -5488,8 +5488,11 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, if (ret == GS_ERROR) return GS_ERROR; /* If we have gimplified both sides of the initializer but have - not emitted an assignment, do so now. */ - if (*expr_p) + not emitted an assignment, do so now. */ + if (*expr_p + /* If the type is an empty type, we don't need to emit the + assignment. */ + && !is_empty_type (TREE_TYPE (TREE_OPERAND (*expr_p, 0)))) { tree lhs = TREE_OPERAND (*expr_p, 0); tree rhs = TREE_OPERAND (*expr_p, 1); diff --git a/gcc/testsuite/gcc.dg/pr87052.c b/gcc/testsuite/gcc.dg/pr87052.c index 18e092c4674..796fe6440c1 100644 --- a/gcc/testsuite/gcc.dg/pr87052.c +++ b/gcc/testsuite/gcc.dg/pr87052.c @@ -23,8 +23,7 @@ void test (void) const char d[0] = { }; - /* Expect the following: - d = ""; */ + /* Expect nothing. */ const char e[0] = ""; @@ -36,6 +35,7 @@ void test (void) /* { dg-final { scan-tree-dump-times "a = \"\\\\x00ab\";" 1 "gimple" } } { dg-final { scan-tree-dump-times "b = \"a\\\\x00bc\";" 1 "gimple" } } { dg-final { scan-tree-dump-times "c = \"\";" 1 "gimple" } } - { dg-final { scan-tree-dump-times "d = { *};" 1 "gimple" } } + { dg-final { scan-tree-dump-times "d = " 1 "gimple" } } + { dg-final { scan-tree-dump-times "d = {CLOBBER\\(eol\\)}" 1 "gimple" } } { dg-final { scan-tree-dump-times "e = " 1 "gimple" } } { dg-final { scan-tree-dump-times "e = {CLOBBER\\(eol\\)}" 1 "gimple" } } */