From patchwork Sat Nov 30 04:43:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 102170 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 421523858D39 for ; Sat, 30 Nov 2024 04:44:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 421523858D39 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=Vdm4ZCCl X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by sourceware.org (Postfix) with ESMTPS id 418C23858D29 for ; Sat, 30 Nov 2024 04:43:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 418C23858D29 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=quicinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 418C23858D29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732941822; cv=none; b=CKcUdzNz65eCu23iulm507OtcqTsxtAwYOB4nxRBfM6ept6p3ZLBsGRgnMJdBL2X+2zug+sNSOKE0ZOhG7XXuSJp4ntwYeIH60ucNcB2vdyTXPyzY6LnbRMZjtKXqxc2SI4HIAvIlKKOhXfW+RJN8YFpCKYtymoYDeup9TyAO6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732941822; c=relaxed/simple; bh=1pavxYjyjzK/O5w7rsBc7v9nWJOrsU1ffOe/KrCi/f8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=e4b3xt+tX74ciYjw8H9FoyH1AHtcm04JiF1/2bZlSGgZUhWXlyQ8MVOfhwCf/98Q5qE6lH8cq3iL9PgC7IY/LzBw9uzsK9VLzJl6iH4ccYmUgRb06c3qMI+YqlUjccR4FYAOGJ994ikHR9rTlB5mTydAZ5mI1OE4u6v+xhpOnnw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 418C23858D29 Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4AU4dhDn016888 for ; Sat, 30 Nov 2024 04:43:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=qcppdkim1; bh=nf1fyKNRG1SeYDwpWeHS/l Emc4UoLnd20klmPcXjfr0=; b=Vdm4ZCClcRe94MD02dgY+tfxXF8qjKkFLl6GkL DBrH6dxxLSpIb0wggegaXdusINY+Q1fhz3EfOqugT25mSsmNbpu9yfQ928tAOpM+ sWFh7pZbtCnen+q5pdZvJ1GaP5SK0xSD2IzlHm2ppcMr7vUKoPNH5FAIY8rnYApz JzOmhbPiXTEj51gMe8khvWCDnIckyPGOFu1RxG9tM6RTi+YN3RKO38bd+zCa+MMQ 0Cuq7fZU9vkG42uOyeK+iiPWLTqEKWNxRe9rA7s7RkgHreX9T2caIYgGAx9WrbZh koQtqcikBSCT1WAcvTyYvmzPIu66kwPZpu/RbiNEy+E5Du1g== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 437uvjr052-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 30 Nov 2024 04:43:40 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA03.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4AU4hdaT026485 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 30 Nov 2024 04:43:39 GMT Received: from hu-apinski-lv.qualcomm.com (10.49.16.6) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Fri, 29 Nov 2024 20:43:39 -0800 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH] gimplefe: Error recovery for invalid declarations [PR117749] Date: Fri, 29 Nov 2024 20:43:27 -0800 Message-ID: <20241130044327.1640070-1-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: mGl51elEHVB3dKiElH8sITbg4R04Dk5w X-Proofpoint-ORIG-GUID: mGl51elEHVB3dKiElH8sITbg4R04Dk5w X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 suspectscore=0 mlxlogscore=680 impostorscore=0 adultscore=0 phishscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2411300036 X-Spam-Status: No, score=-14.1 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org c_parser_declarator can return null if there was an error, but c_parser_gimple_declaration was not ready for that. This fixes that oversight so we don't get an ICE after the error. Bootstrapped and tested on x86_64-linux-gnu. PR c/117749 gcc/c/ChangeLog: * gimple-parser.cc (c_parser_gimple_declaration): Check declarator to be non-null. gcc/testsuite/ChangeLog: * gcc.dg/gimplefe-55.c: New test. Signed-off-by: Andrew Pinski --- gcc/c/gimple-parser.cc | 12 ++++++------ gcc/testsuite/gcc.dg/gimplefe-55.c | 11 +++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/gimplefe-55.c diff --git a/gcc/c/gimple-parser.cc b/gcc/c/gimple-parser.cc index 4763cf23313..78e85d93487 100644 --- a/gcc/c/gimple-parser.cc +++ b/gcc/c/gimple-parser.cc @@ -2208,7 +2208,12 @@ c_parser_gimple_declaration (gimple_parser &parser) specs->typespec_kind != ctsk_none, C_DTR_NORMAL, &dummy); - if (c_parser_next_token_is (parser, CPP_SEMICOLON)) + if (!c_parser_next_token_is (parser, CPP_SEMICOLON)) + { + c_parser_error (parser, "expected %<;%>"); + return; + } + if (declarator) { /* Handle SSA name decls specially, they do not go into the identifier table but we simply build the SSA name for later lookup. */ @@ -2253,11 +2258,6 @@ c_parser_gimple_declaration (gimple_parser &parser) NULL_TREE); } } - else - { - c_parser_error (parser, "expected %<;%>"); - return; - } } /* Parse gimple goto statement. */ diff --git a/gcc/testsuite/gcc.dg/gimplefe-55.c b/gcc/testsuite/gcc.dg/gimplefe-55.c new file mode 100644 index 00000000000..120f4ec0ac9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gimplefe-55.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple" } */ + +/* PR c/117749 */ +/* Make sure we don't ICE after not have a full local + declaration in gimple fe. */ + +__GIMPLE +void foo ( ) { + int ; /* { dg-error "" } */ +}