From patchwork Tue Feb 11 08:47:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 106320 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 1218E3858CDA for ; Tue, 11 Feb 2025 08:50:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1218E3858CDA 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=DMAXIRuG 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 1E2B33858D1E for ; Tue, 11 Feb 2025 08:48:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1E2B33858D1E 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 1E2B33858D1E 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=1739263683; cv=none; b=azhm2w/TRNgb8Hm59lBbpoGJdc7TqQSZpA0QGd509O207Z1K8rRnSC00ihBrJZ6o+7cPCTKCUL2fJnTqwZEfBwnabLZ42qCC9VJmwCq7+cShdLzYU/rk3UnRPTd3SBJMV2BFcCUAzYwGTagtkTGZthSc8Oyi9AoPW5Q+wXAFHB0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739263683; c=relaxed/simple; bh=QmN7AAuZ2QUyImtgufEN2fn4XKOrVSVSsKiEZoGF3D0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=t3GP/RmoKr7shUReXicRrGGet5OI1luQ7s1c8slmvUbvbKGXaRWmWCbcScRRJE+f/ldDXGHTmPR1r7A4Om1qrw2scizpcLLOv2n3rl3IZLxmaKCZEprJGb2BAdgQuX1vL4vN8GcJFXZF23r+m2k0d3RwA1B0JjSOVTB37C+4MSE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E2B33858D1E Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 51AKF50s009211 for ; Tue, 11 Feb 2025 08:48:02 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=BerrnyOHSlSFcTwATvK6oi RRTqC5+AvSl3yvxfloNy0=; b=DMAXIRuGgwWS2nIGIyHn0fRg9aX5y0hoMxJT4w gR7ZiR7a78vZlrSfs1Z6OYEX21PwRu1m+AJcFHHGr7WNkbfo011vT38IeyJI+Noe p7dU03xpf896Nf/2cLjCV9qRAfPEBcej8JKqHLRZuWzFVTIBegBa1IQxSx9MweDN ICENf0mmy0V+KE8nDHcaxTO/MBI1obUJQY1KBatYhgkkXsxoP8+g3tJJZdycN6ab JbN15AFbol8b8xvzhgc4wECoMOCNWYutUeoEanqzugOppn7pZ4jhwLTwHs5sA3vj ksaO4aJ1136Kr5ZcfRSlLrtCUf73+xr0l0RwiJUOUtP7OIjA== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 44p0dqf7a6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 11 Feb 2025 08:48:01 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA05.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 51B8m1qc018664 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 11 Feb 2025 08:48:01 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; Tue, 11 Feb 2025 00:48:00 -0800 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 1/2] libcpp: Fix handling of `deferred` pragmas with -traditional [PR79516] Date: Tue, 11 Feb 2025 00:47:46 -0800 Message-ID: <20250211084747.149547-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: nalasex01a.na.qualcomm.com (10.47.209.196) 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: nD5dA-1lqqXC3W2e5AZxR95gcfrj0pRf X-Proofpoint-ORIG-GUID: nD5dA-1lqqXC3W2e5AZxR95gcfrj0pRf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-11_04,2025-02-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 malwarescore=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 mlxlogscore=722 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2501170000 definitions=main-2502110053 X-Spam-Status: No, score=-14.2 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 The problem here is with deferred pragmas, libcpp would inject a PRAGMA_EOL before the end of the new line in the tokens stream but traditional cpp path does not use that path except when dealing with directives. In this case we call out to handle `#if` directive and that token got added due to the change of line #. So at the end of a directive, we need to set in_deferred_pragma to false as traditional cpp path handles the new line itself. Bootstrapped and tested on x86_64-linux. PR preprocessor/79516 libcpp/ChangeLog: * directives.cc (end_directive): Also set in_deferred_pragma to false with traditional cpp. gcc/testsuite/ChangeLog: * c-c++-common/cpp/pragma-message-trad.c: New test. Signed-off-by: Andrew Pinski --- gcc/testsuite/c-c++-common/cpp/pragma-message-trad.c | 9 +++++++++ libcpp/directives.cc | 2 ++ 2 files changed, 11 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/cpp/pragma-message-trad.c diff --git a/gcc/testsuite/c-c++-common/cpp/pragma-message-trad.c b/gcc/testsuite/c-c++-common/cpp/pragma-message-trad.c new file mode 100644 index 00000000000..0478e6fc7c7 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/pragma-message-trad.c @@ -0,0 +1,9 @@ +/* { dg-do preprocess } */ +/* { dg-options "-traditional-cpp" } */ +/* PR preprocessor/79516 */ + +#pragma message "OK" + +#if 0 +#pragma message ("Not printed") +#endif diff --git a/libcpp/directives.cc b/libcpp/directives.cc index 6b0d691f491..9c0f77ab017 100644 --- a/libcpp/directives.cc +++ b/libcpp/directives.cc @@ -323,6 +323,8 @@ end_directive (cpp_reader *pfile, int skip_line) /* Revert change of prepare_directive_trad. */ if (!pfile->state.in_deferred_pragma) pfile->state.prevent_expansion--; + /* No longer inside a deferred pragma. */ + pfile->state.in_deferred_pragma = false; if (pfile->directive != &dtable[T_DEFINE]) _cpp_remove_overlay (pfile);