From patchwork Thu Mar 23 17:25:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 66817 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 7260B3850876 for ; Thu, 23 Mar 2023 17:26:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7260B3850876 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679592400; bh=9DfL+H+NCaasAfXl00KKY+MYmDCH8SKc9UpsFdKKrg8=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=BjyayJBDs3Q5oHY1bgVsINiADlsv5JH/0YM1cwqPv5ZJ6o/Q8ejNHzT/W3sSHLKPK L2DGdQSkdS7i5G5tR8r2n6/rNBMtD6KOIZwnXxBlkqavuR9F4JiZ4vakWLvHKiCAT1 icQuTlByCn4zeehS29nxiFRcaxNy+AYd/AYYEtZY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 1C34B3858CDB for ; Thu, 23 Mar 2023 17:26:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1C34B3858CDB Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32NBpg2F024001 for ; Thu, 23 Mar 2023 10:26:08 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3pg9urcuax-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 23 Mar 2023 10:26:07 -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.42; Thu, 23 Mar 2023 10:26:06 -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.42 via Frontend Transport; Thu, 23 Mar 2023 10:26:06 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.67]) by maili.marvell.com (Postfix) with ESMTP id D59933F706C; Thu, 23 Mar 2023 10:26:05 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] c: [PR84900] cast of compound literal does not cause the code to become a non-lvalue Date: Thu, 23 Mar 2023 10:25:57 -0700 Message-ID: <20230323172557.3415682-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: 2mQBeQfPWufkz5cQZYDQwygeCAt-PxfG X-Proofpoint-ORIG-GUID: 2mQBeQfPWufkz5cQZYDQwygeCAt-PxfG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-22_21,2023-03-23_02,2023-02-09_01 X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The problem here is after r0-92187-g2ec5deb5c3146c, maybe_lvalue_p would return false for compound literals which causes non_lvalue_loc not to wrap the expression with a NON_LVALUE_EXPR unlike before when it return true as it returns true for all language specific tree codes. This fixes that oversight and fixes the testcase to have the cast as a non-lvalue. Committed to the trunk as obvious after a bootstrap/test on x86_64-linux-gnu. PR c/84900 gcc/ChangeLog: * fold-const.cc (maybe_lvalue_p): Treat COMPOUND_LITERAL_EXPR as a lvalue. gcc/testsuite/ChangeLog: * gcc.dg/compound-literal-cast-lvalue-1.c: New test. --- gcc/fold-const.cc | 1 + gcc/testsuite/gcc.dg/compound-literal-cast-lvalue-1.c | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/compound-literal-cast-lvalue-1.c diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index 02a24c5fe65..5b9982e3651 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -2646,6 +2646,7 @@ maybe_lvalue_p (const_tree x) case LABEL_DECL: case FUNCTION_DECL: case SSA_NAME: + case COMPOUND_LITERAL_EXPR: case COMPONENT_REF: case MEM_REF: diff --git a/gcc/testsuite/gcc.dg/compound-literal-cast-lvalue-1.c b/gcc/testsuite/gcc.dg/compound-literal-cast-lvalue-1.c new file mode 100644 index 00000000000..729bae24316 --- /dev/null +++ b/gcc/testsuite/gcc.dg/compound-literal-cast-lvalue-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-std=c99" } */ +/* PR c/84900; casts from compound literals + were not considered a non-lvalue. */ + +int main() { + int *p = &(int) (int) {0}; /* { dg-error "lvalue" } */ + return 0; +}