From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=marvell.com 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=9DfL+H+NCaasAfXl00KKY+MYmDCH8SKc9UpsFdKKrg8=; b=ULbou6sOmZb2g1LFRmToJLhR5v6Nf4KJNcwCAbker93pnnGfdDcl/h7/Z1gnkK+0UIcP 4VPYpN04yFid2cgEoK4jWYdI15aWVPgmj8ePd9z6G3Kph/DfpknLJWXuUlhg2uOzX5HZ 8XeiJCHIJ6TvQddXSQVuzghLIn7vY9MXaGpHPkQBAHqqdubXHeawiK/T+3/gkK4l24VC cT0bN/QLY/kFNvToYBArgqjyenI1g4lxhXzhIxbWcc4goFav2KNPMOc72qwAC/uaZcZg 7xVdeknX3g3KW4CLgTkXHmM3POkTcZ0fNbTPwqaGknuJkGhb1LaxIALSBJuZwvw7ZuWw cA== 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) From: Andrew Pinski 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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 List-Id: 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; +} -- 2.31.1