From patchwork Tue Feb 11 08:47:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 106321 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 114093858C66 for ; Tue, 11 Feb 2025 08:50:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 114093858C66 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=kOi5eYYm 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 3B4783858CDB for ; Tue, 11 Feb 2025 08:48:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3B4783858CDB 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 3B4783858CDB 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=O156OeDpdIWGnJ3jJD41W6yM8FdggB4OHCsEKPOAywwqOljs5SxwBfvgx3F4q03YilarRz5W0RT6pIKNZUwQNlcCwqdeJ4LOgNZuCBgU5j9ZKT/7sIRjgPrJyrQqS17ArjQHaCLVTXTg96VjHlgDx34THxy7D8ay7c4CJFkcTlg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739263683; c=relaxed/simple; bh=ggy2Xi0i9NgGIGeps1k3wh6s27b4vG/GPJiiHTYfdwg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ko6HJEKG8vduOGt0/NMrNVlVWWwDV7RwmQZD9PQcopw39I4x4YfnaExBgo4kcba5YKz1I6wx88COwWMaR9nCNWzAdFQRNFVWsd85unIxF+orIdQH2FKDsd7TG6fmuJ+ADIAntGtQW3oVlIWwuIGe6u7Ju7+KFHCX1uCBdwHUbIU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B4783858CDB Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 51AKSatd023509 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:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= /HIlbuit4BEwTXkb03M54KgTTpwYzE86+IPojfMUtzA=; b=kOi5eYYmPKwbdmQl XyoDN9KPpHZY1f6YPIFwkfuVnocR1/RAPj5hxkukDC2c/V3VY+usEhfVJMOgdPD7 yaSn6GnoU7yIL59/IOc2ksbZ7Yo/91NC+9SeophJlZM9oMztA1bk5eg+823dC+N6 5W3mDZD0pO0ljql8acTBlp5hTKlldzfIS8mqwUBpA97+wsBGkHLjc+NtLqL/h5PI 2gMKdXanRYA/z7eFjEYWK6CiiL66QVhknGDz5fjt9w9CWAm1AkhlB4sFihNNSr6x KPgXJ6oRfl6MKTK1Tr62MgcVuGNH0KEMeykvhi5dr5uDECbMsIK3Bm8kNlmIW3cc ktY4Pw== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 44p0dyq2t0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 11 Feb 2025 08:48:02 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA01.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 51B8m1lp007036 (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:01 -0800 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 2/2] libcpp: Fix incorrect line information for traditional cpp and #include [PR100904] Date: Tue, 11 Feb 2025 00:47:47 -0800 Message-ID: <20250211084747.149547-2-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250211084747.149547-1-quic_apinski@quicinc.com> References: <20250211084747.149547-1-quic_apinski@quicinc.com> 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-ORIG-GUID: y4FmcvK-vE6bhYNUfTBwnJDoW9xCI-a9 X-Proofpoint-GUID: y4FmcvK-vE6bhYNUfTBwnJDoW9xCI-a9 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 suspectscore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 mlxscore=0 priorityscore=1501 spamscore=0 adultscore=0 phishscore=0 malwarescore=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 After r7-1651-gac81cf0b2bf5efdd7, the location for the error for #include would be the location on the token. Except in traditional cpp, the location information for directives is all messed up because first libcpp processes the directive line in traditional and copies it to a new buffer and then does the lexing using the ISO lexer. This means the location information for the tokens are wrong and should just grab the location of the directive line instead. This patch does exactly that. Uses directive line location for traditional cpp when parsing the include. Bootstrapped and tested on x86_64-linux-gnu. PR preprocessor/100904 libcpp/ChangeLog: * directives.cc (parse_include): Use the directive line location for the location in traditional cpp mode instead of the location of the token. gcc/testsuite/ChangeLog: * gcc.dg/cpp/missing-header-trad-1.c: New test. Signed-off-by: Andrew Pinski --- gcc/testsuite/gcc.dg/cpp/missing-header-trad-1.c | 10 ++++++++++ libcpp/directives.cc | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/cpp/missing-header-trad-1.c diff --git a/gcc/testsuite/gcc.dg/cpp/missing-header-trad-1.c b/gcc/testsuite/gcc.dg/cpp/missing-header-trad-1.c new file mode 100644 index 00000000000..d77cc5fe228 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/missing-header-trad-1.c @@ -0,0 +1,10 @@ +/* { dg-do preprocess } */ +/* { dg-options "-traditional-cpp" } */ + +/* PR preprocessor/100904 */ +/* Make sure we error out on the correct line + for traditional cpp. */ + +#include "nonexistent.h" /* { dg-error "-: nonexistent.h" } */ + +/* { dg-message "terminated" "terminated" { target *-*-* } 0 } */ diff --git a/libcpp/directives.cc b/libcpp/directives.cc index 9c0f77ab017..d4a5ab1cbec 100644 --- a/libcpp/directives.cc +++ b/libcpp/directives.cc @@ -841,7 +841,14 @@ parse_include (cpp_reader *pfile, int *pangle_brackets, /* Allow macro expansion. */ header = get_token_no_padding (pfile); - *location = header->src_loc; + + /* The location for traditional is the directive line as the + token line information for the temporary buffer. */ + if (CPP_OPTION (pfile, traditional)) + *location = pfile->directive_line; + else + *location = header->src_loc; + if ((header->type == CPP_STRING && header->val.str.text[0] != 'R') || header->type == CPP_HEADER_NAME) {