From patchwork Tue Sep 16 18:40:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 120389 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 4528F385703B for ; Tue, 16 Sep 2025 18:41:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by sourceware.org (Postfix) with ESMTPS id 17129385735D for ; Tue, 16 Sep 2025 18:40:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 17129385735D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=oss.qualcomm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oss.qualcomm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 17129385735D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758048051; cv=none; b=tKGw5w/Pj170q2IyIulF8zHPB47cQO4tSkyofEqBMZnuX/gMwRzsbt14kLr09lZBA9VzfrgcYgKY46e5z32ClpxDclh72CTYyZOe61VXtIlpMEJaS1A2hEpse+BZRExv73jXWkTt9K6aZdnKq/4KhhcUORtobfwcW6PuZ430DYI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758048051; c=relaxed/simple; bh=Zs3R+vXpcvXhvjOg+T3ZhFVNl3yQffa90RbF//URtmQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Q0LNSvMO+OPl8ERrO4WMl7F69n/o4qFSJYh0VINOxxWmk0SZFVN/GslzSL0PPFs79IxFT2y9Squ0VJkm8yKYdmbDLlSUTiJvqv43R6PG2rJKxjGsNgAiywMpGSiFGyj1G33IC57Md+4yu2ZUh8gIGlUxufO0BaH49XJNGXOnuu4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 58GGLMYY032339 for ; Tue, 16 Sep 2025 18:40:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=qcppdkim1; bh=+lM0Xz6lXIHsFmDErdgcXNHEFw7UwxIZu0W GvcFosq0=; b=cFWd8+9K9y0e78SakpoUxKp2uvYqZEMf6mOdtAjhSKnSUr8pD28 r3mQh7DzIfM3sa/71fz/o05zSHS9fWFiVPq6il397dgR8jiYxHZutkdDrehYWQiI FcE++h4c/IUAxf+dt+LfOP0RW7GexKoYZgzbrL2dwW+/03a4J8DoxRf0ZQQc2Yvz ORkxy45NW37iGLOFZRytkk7lB2niLCjDLMIbWwToUf0ojH3IHDHfR3VFXveWIW6t +Iz8s0nvyMBZk7Aj1CIkQbTIZIZZcrV86lTemn2bciKOfJuVgcJH6rMryqGG5DKj kFzaK6srvyHVgX7YkjhOnkWc8DdNdqABrKg== Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 497bb5rff0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 16 Sep 2025 18:40:46 +0000 (GMT) Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2649a245f3fso22877735ad.1 for ; Tue, 16 Sep 2025 11:40:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758048045; x=1758652845; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+lM0Xz6lXIHsFmDErdgcXNHEFw7UwxIZu0WGvcFosq0=; b=E0z1A/Z09AowN++mhbrzwvXQJVM1Bu4x9xgmuueE4UY0bL5Bj4Mrp4KEC2mHiQLt4i YbkVudrR1lxz+q+aYe/5jSc9IZpwjom+wYlSnVhGpDpFs17NRXfPBSfrVZKEb/YS64li PsOE0Jz9c9WLxJYqcBf5m2WAJc7WxZENjaOMFiKNjSEw+HeZiDZAeJkYiTJQKAx3vJ4b 9mPxjtDcw0+2w2QetinCKf0h6D44FvYLeygbb9PGSRiM2aKlWb64X+aXGUuUjRjFGzme e1eal6d2RP5vosdMquY8umhjYmUlxfKD7N0TcCftPpBeZIuezrbwmI/xEEynMp4ROH9/ zPAw== X-Gm-Message-State: AOJu0YxMDtY6+GNnHgLaT+H3Pd39SCvSE2sVFT2sg/5Cm9pq7r5cCoFV zqD4/NxLubP3C0m/ct9uBl9wOhz/2mxSiIbCAy0Fjd1uGdvK+4c21Bqpg/1blyl1rvYlzPheTUS k7XxFGjqP42Ka0lm63Uul9R26LquY5cGx50vKeSRrR+MXdYqRJJUtcVGlellkHyLA604G X-Gm-Gg: ASbGncu8oBo5eImno1Rgrk4CYQwlUfJFU3datzKHzJki05a9QMN8tKEvhyX37UXPK83 9lHcEgjRnd14y9KmhAsKYr30pTWPcJknSwZi3qcIAZ953AZQACy7UbkrWWJqUQkm+a/dbDkKgZ6 NOgOcePeiQMXg+jOaXwkIm3Gjtm7hEdR+/0h6SJMBmpw1lXVtj8IjmaS8VXb686RzIiwNfWXOXv GUmnDQnCYgwDRQd7v5cV3vlXsGzAHlWXmfgP4N9uMyhWESx2ma5MsZSi/kGgtZ8L9kRa0yi5sfP a6Y8JyNlRdGnxacfdJso9FHEsCxccCyiO5k7Bv7WkCKspI7ufWhUSOtsA5d92nR1b5U= X-Received: by 2002:a17:903:1b67:b0:25d:885:5b6b with SMTP id d9443c01a7336-25d28007a20mr229695465ad.58.1758048044622; Tue, 16 Sep 2025 11:40:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGmVBMbfXZhWcY3D0yV1IdnQRSyROA8oUCKGxBVhm5HQE/25r/4pL336eYa+TyQmK//rFfU8A== X-Received: by 2002:a17:903:1b67:b0:25d:885:5b6b with SMTP id d9443c01a7336-25d28007a20mr229695265ad.58.1758048044024; Tue, 16 Sep 2025 11:40:44 -0700 (PDT) Received: from xeond2.wrightpinski.org ([98.97.43.202]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-265819a61besm74982695ad.53.2025.09.16.11.40.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Sep 2025 11:40:43 -0700 (PDT) From: Andrew Pinski To: gcc-patches@gcc.gnu.org Cc: Andrew Pinski Subject: [PATCH] c: Reject gimple and rtl functions as needed functions [PR121421] Date: Tue, 16 Sep 2025 11:40:30 -0700 Message-ID: <20250916184030.1002454-1-andrew.pinski@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Proofpoint-GUID: r4MsuTQrDzZEnXy0PuhueiOyYY6M5KNN X-Proofpoint-ORIG-GUID: r4MsuTQrDzZEnXy0PuhueiOyYY6M5KNN X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwOTE2MDE1MiBTYWx0ZWRfXxqD+hOx5d62A iu7maF7b9JXr4rUvUQOV5QuAxqYMkUmF5QSqSkCOtcwRYvSjB8v6QuKG2GxTxYv38aKjd4K2g4l 9h9SKeaX5WzcuVVDEgKNHW8GxKjsAHJQfP2dFPyaQCOJik1VE4L6udQnQ4wptag3PvfyFx6O/45 lQFlXIOQDyuVKbYQ1xXJ9pKgMEKy0ZaHQEe66/Pzs5KpNHRcd/tTwFIKB+GE+8bL/LTJbMZbtBE JVb1lojO7jqEaBrMJu9sRaS9rfzLHesXyj2RB7+o/S5k5t1JC9XCyUWHJCdAtZpb/r1JKojaO2y 255l9onEMj3BIkMx9gUJW2/KdV+OsGkRU5PnAxP9J1zB3Lyz3g+IjBG0+vN797KinfjIlH4wbee 7gUjP/gl X-Authority-Analysis: v=2.4 cv=ZfMdNtVA c=1 sm=1 tr=0 ts=68c9af2e cx=c_pps a=MTSHoo12Qbhz2p7MsH1ifg==:117 a=vt1orro8+gjQ+DRoXK0hhA==:17 a=yJojWOMRYYMA:10 a=EUspDBNiAAAA:8 a=RO8tJBBWaMRDb8my72kA:9 a=GvdueXVYPmCkWapjIL-Q:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1117,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-09-16_02,2025-09-16_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 adultscore=0 phishscore=0 bulkscore=0 impostorscore=0 malwarescore=0 clxscore=1015 priorityscore=1501 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2507300000 definitions=main-2509160152 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, 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: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org These two don't make sense as nested functions as they both don't handle the unnesting and/or have support for the static chain. So let's reject them. Bootstrapped and tested on x86_64-linux-gnu. PR c/121421 gcc/c/ChangeLog: * c-parser.cc (c_parser_declaration_or_fndef): Error out for gimple and rtl functions as nested functions. gcc/testsuite/ChangeLog: * gcc.dg/gimplefe-error-16.c: New test. Signed-off-by: Andrew Pinski --- gcc/c/c-parser.cc | 11 ++++++++++- gcc/testsuite/gcc.dg/gimplefe-error-16.c | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/gimplefe-error-16.c diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index f1aaab12e6e..df44a915ed4 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -3222,7 +3222,7 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, else fnbody = c_parser_compound_statement (parser, &endloc); tree fndecl = current_function_decl; - if (nested) + if (nested && specs->declspec_il == cdil_none) { tree decl = current_function_decl; /* Mark nested functions as needing static-chain initially. @@ -3235,6 +3235,15 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, c_pop_function_context (); add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl)); } + else if (nested) + { + if (specs->declspec_il == cdil_rtl) + error ("%<__RTL%> function cannot be a nested function"); + else + error ("%<__GIMPLE%> function cannot be a nested function"); + finish_function (endloc); + c_pop_function_context (); + } else { if (fnbody) diff --git a/gcc/testsuite/gcc.dg/gimplefe-error-16.c b/gcc/testsuite/gcc.dg/gimplefe-error-16.c new file mode 100644 index 00000000000..4cdeac889c8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gimplefe-error-16.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple" } */ +/* PR c/121421 */ +/* Gimple functions cannot be nested functions. */ + + +void main(void) +{ + void __GIMPLE b(){} /* { dg-error "cannot be a nested" } */ +}