From patchwork Wed Sep 13 22:29:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 139126 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:a8d:b0:3f2:4152:657d with SMTP id gr13csp123631vqb; Wed, 13 Sep 2023 15:30:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5chfmdlAN5mIT2RIdx2WYxzSUJhYw9AqRoDZa7naihBpWN7Enh1A9XNZDynPlqftx1c0q X-Received: by 2002:a2e:9612:0:b0:2b5:9778:7ce2 with SMTP id v18-20020a2e9612000000b002b597787ce2mr3202779ljh.15.1694644211484; Wed, 13 Sep 2023 15:30:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694644211; cv=none; d=google.com; s=arc-20160816; b=cJpxtfaeiDiqV41IGJejRKgZ6ez4ZHdSVptYacLWBV+FPcYIUumRDwJeAwUPLVh+wK I0JtAoeOMdAzF5L0sm+hiVKIOA+AkBEPYun+IKpNpD11Gk46PZpZH3UE73t69mNfr6CO qneHTO3qVdNePKonVr65HOswPs1DdBZAHGXw2wFgq1/hPLsjfZHB7/tKhH25cDqVvoRX xAoAC6R5T+yb0w/LSHRdnPOmiIsa51Nw6k48qBPCraqPgsBebRl1vqoCov3GMsffPVE4 rUeuDb+BguIwoHErQFJ96IA4efDzaDowYqh9VY+q2ASX597g8ovAblyQXxAj6yU9nf4V k56g== 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=vaIivbJh72pC7kAghn9qraCthEqecYNV5jaWrVGbgqE=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=k9j5RqZ3xtPtDv9ZiXJZSr4ylKE8CuLUf2FYWQLNUdtvZ8Aw3vfCu+Jlh1CNMnwoM2 T9phmZ1fMgZLI24WTNLbZYDXMVO93yIMSBSBSi7hHAU+KedmzDNXAoPakCEdFIATQVM/ 81bl1/VjHqf8acSCHnzCvAWGvj27KuaA+zJVJo18q2piwqJZfWy4+yyIOUgNnzh+UpdB fNml9r1iRAmNkRMOhBptwPHtu1I3WZFUJOUvvxmVTRCWqJe2+lHWvmq5mn6xjnRUtiRs 3cV27ASXpvxlnYIZlYjaDB5kQCh8697mZtLjZnZNiav8bJ5XrfC32M+qulKMJIzMuwsF cA6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CiJuyGGR; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id o15-20020a1709061d4f00b0098d22334ee0si114115ejh.797.2023.09.13.15.30.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 15:30:11 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CiJuyGGR; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 224F53858C5F for ; Wed, 13 Sep 2023 22:30:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 224F53858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694644210; bh=vaIivbJh72pC7kAghn9qraCthEqecYNV5jaWrVGbgqE=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=CiJuyGGRD+lJZPgS63n99AYRx4nmv3WYYlcPbqlVNnFlmH+jpWMTZO+/9y+DMpPsb B373r73E7XGLF6uGNGihq1vi5wwj9pwEOgNR7fqgN2jxcYFQ345NdMbzuf1R0cPvcD yJpoahiGq2RYDFjhaTIn4h0+jLtZ2Zfqh/dY2WH4= 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 B3B9C3858CDA for ; Wed, 13 Sep 2023 22:29:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B3B9C3858CDA Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38DIHHX0026292 for ; Wed, 13 Sep 2023 15:29:24 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3t2y86534w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Wed, 13 Sep 2023 15:29:23 -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.48; Wed, 13 Sep 2023 15:29:21 -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.48 via Frontend Transport; Wed, 13 Sep 2023 15:29:21 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 7E25F3F704A; Wed, 13 Sep 2023 15:29:21 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] Improve error message for if with an else part while in switch Date: Wed, 13 Sep 2023 15:29:11 -0700 Message-ID: <20230913222911.1516503-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: BUeQ5wgJs0o1xovyoMg1nMpSJNzdz8zg X-Proofpoint-GUID: BUeQ5wgJs0o1xovyoMg1nMpSJNzdz8zg X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-13_17,2023-09-13_01,2023-05-22_02 X-Spam-Status: No, score=-14.6 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_PASS, 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.30 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: INBOX X-GMAIL-THRID: 1776963248802707492 X-GMAIL-MSGID: 1776963248802707492 While writing some match.pd code, I was trying to figure out why I was getting an `expected ), got (` error message while writing an if statement with an else clause. For switch statements, the if statements cannot have an else clause so it would be better to have a decent error message saying that explictly. OK? Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * genmatch.cc (parser::parse_result): For an else clause of an if statement inside a switch, error out explictly. --- gcc/genmatch.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index a1925a747a7..03d325efdf6 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -4891,6 +4891,8 @@ parser::parse_result (operand *result, predicate_id *matcher) ife->trueexpr = parse_result (result, matcher); else ife->trueexpr = parse_op (); + if (peek ()->type == CPP_OPEN_PAREN) + fatal_at (peek(), "if inside switch cannot have an else"); eat_token (CPP_CLOSE_PAREN); } else