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: 74129 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp3040516wrt; Thu, 23 Mar 2023 10:27:00 -0700 (PDT) X-Google-Smtp-Source: AK7set9NeDM94McoDkxXaJeCyEtcWCekqGEEAeP80gQbj7z+tTVYoS3imhh9r2dY7gm9PRrlSmKK X-Received: by 2002:a17:906:d20e:b0:8b1:2c37:ae97 with SMTP id w14-20020a170906d20e00b008b12c37ae97mr11592953ejz.43.1679592420849; Thu, 23 Mar 2023 10:27:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679592420; cv=none; d=google.com; s=arc-20160816; b=b7J26Dn43UcTjDRpHxN1FXXDdc8+GZLzQhYEmB9xNUA5RPkZn9RHfXlKYayxoB1iJC JReqM3kKBZG80y3CJKJn3Yhv6cjHaRJdsmeRd7+8a8acadriB+plbqJjLZF/rzwXXoly oBN0jId5ZEOHpN0bEEDAtVf/G1e8mbCOEuy0C1iopHSnV+9G5VRhbpwSQviX47kD67rh e+EnB2xFOc7t0c7uTDpI8HbOaukRyK78hyyejm2DrMvMbCaAECRJe6uT67Qs/KvNa8fy 35wSUOs5HbnC9MbhvKIJRM+ihic6zfgf9ubfWMebiVxYf1RZNrbA6o4vqZZkTKWNSAl+ FBIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=9DfL+H+NCaasAfXl00KKY+MYmDCH8SKc9UpsFdKKrg8=; b=NdqCYBocujnINQU+9cbxUVBhw2f55m0WxBhDqYOwKa9OcgdbqkGyGsu2csuLPzLtnw 6wMouluoRwlfFmBlfxB5GyfE1wUkw5HTgxBOljeVWo2t0X/2dAYnOaZ6oI4NPaDU/BWt HUiG0rWs9mc1E7sosTg8pMeT/gqApSOSTueumyhST5QrqZxP8xTWlihtvv4TiRVtEPey +zMOXhzo7g387KqYpWiRbLB/vAlm4bbkeOREyuEUnGpw9hKeKxeQdPmmRuXFSzJBeAaj 7I/JgPVkjnFBTzKturWSs0BzT8q2x7JKxr3aA61yFfJMXofr7oIJBUbi303xhrUEd9us auIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=p8l8eWS4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id he31-20020a1709073d9f00b0093a6b7c4e9csi8805386ejc.914.2023.03.23.10.27.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Mar 2023 10:27:00 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=p8l8eWS4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D601C38708B4 for ; Thu, 23 Mar 2023 17:26:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D601C38708B4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679592415; 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=p8l8eWS4h5J6W4HiU7W21XQ0aP0DWQ1kldXiRgm2TIZ7rPRLOKxNwbcfCfMWiKwsn UnFnBd4FN6vyq+DktZMdqS76CvCuQgWecka8ihnPRtqFNNbm0vBeCR4b8qhO6VMr5e qfSvyO0YsVRhqkEolyNDYQke8csiM09kDYWsbLQY= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761180302059040875?= X-GMAIL-MSGID: =?utf-8?q?1761180302059040875?= 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; +}