From patchwork Wed Dec 7 09:30:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helmut Grohne X-Patchwork-Id: 30725 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp76402wrr; Wed, 7 Dec 2022 01:31:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf7GZ96n0JV/ccIIdZkuKAKFjICI0GHp2ljCgoyRrSAS274X/66BMgTi1kz1BagflvTgkL6h X-Received: by 2002:a17:906:3e5a:b0:7c1:19e1:50e6 with SMTP id t26-20020a1709063e5a00b007c119e150e6mr2783863eji.585.1670405499188; Wed, 07 Dec 2022 01:31:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670405499; cv=none; d=google.com; s=arc-20160816; b=lEutfCh46STqYEdY+2HCDaVrvjEh4xRMj/qsz302x2oLcLe/Bh8r3mPdSeJ/DnMFR7 zFOxzMIBPtcgt19YAqzNEIu2sRpO4rKX477ZcvA/mOrCXBSXiD9XXsMLuG7O1jvI4Z/2 AVOHigXbHcW2oQB7EmC1knDPhzhOdqNUCKYkPAjQV77SGJuY4QeicOS1dCWD72LPbays PYxDTRDw2wcXAP47FpaptiLLYQ4P8JJTIWTHNwqf9LMwqdYicMQQX9sGnt1g1OIui4MP hYmqqOM968YHXdMxSH8k1lD2qWYnXWv3m0S7bPJoM1IYXsrst6ct5gJLoLsiNbuMlr+C IYPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:to:from:date:dmarc-filter :delivered-to; bh=9d/RjynsNTDtN7QuzNoZKvHMhytEhOnJ22eZUCuNqqA=; b=R1hodu9xOPolgf6ncMDw0nOcbeh3dPmgR+okehN/EM2g/FcxU+WkxSE02FPAsk4ZfW UijD4KhO1N8wXgIMMnAF1o+T3Wk0nP5I1QbTObm/Hqdz7TqcUouD1RF6cjobetIDhqCS kou013HuCwLH1/BYotl59H3a9K1u6PnWuMY6zaBKumqGZ869FDVZ57hZGdWzgSab/q1v 01/KbVrcX75fLt6C3+zg8sJZ7GLL2mDnHZkqfUZeeIjcWzVvlSvJFKtIC/VGWT/x2L40 jrg7A4MYHJk4UzCYXQwffOmt8gYzvHUtsKWZAQuMJ9qb9anGL3zwwxhZVqbx23nEjne9 DqYQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id js15-20020a17090797cf00b0078d9d67841fsi4358243ejc.400.2022.12.07.01.31.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 01:31:39 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 93FC5383A0FA for ; Wed, 7 Dec 2022 09:31:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from isilmar-4.linta.de (isilmar-4.linta.de [136.243.71.142]) by sourceware.org (Postfix) with ESMTPS id E46173852211 for ; Wed, 7 Dec 2022 09:31:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E46173852211 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=subdivi.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=subdivi.de Received: from isilmar-4.linta.de (isilmar.linta [10.0.0.1]) by isilmar-4.linta.de (Postfix) with ESMTP id CA98A2000AD for ; Wed, 7 Dec 2022 09:31:06 +0000 (UTC) Date: Wed, 7 Dec 2022 10:30:43 +0100 From: Helmut Grohne To: gcc-patches@gcc.gnu.org Subject: [PATCH] preprocessor: __has_include_next should not error out [PR80755] Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751547116456869112?= X-GMAIL-MSGID: =?utf-8?q?1751547116456869112?= If __has_include_next reaches the end of the search path, it causes an error. The use of __has_include_next at the end of the search path is legal and it should return false instead. Bootstrapped and tested on x86_64-linux-gnu. Patched cross toolchain for i686-gnu (hurd) built many packages. gcc/ChangeLog: PR preprocessor/80755 * libcpp/files.cc (search_path_head): Do not raise an error for type IT_INCLUDE_NEXT. * libcpp/files.cc (_cpp_has_header): Deal with NULL return from search_path_head. gcc/testsuite/ChangeLog: PR preprocessor/80755 * testsuite/gcc.dg/cpp/pr80755.c: New test. * gcc.dg/cpp/inc/pr80755.h: Added support file for test. Signed-off-by: Helmut Grohne --- gcc/testsuite/gcc.dg/cpp/inc/pr80755.h | 2 ++ gcc/testsuite/gcc.dg/cpp/pr80755.c | 5 +++++ libcpp/files.cc | 4 +++- 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/cpp/inc/pr80755.h create mode 100644 gcc/testsuite/gcc.dg/cpp/pr80755.c diff --git a/gcc/testsuite/gcc.dg/cpp/inc/pr80755.h b/gcc/testsuite/gcc.dg/cpp/inc/pr80755.h new file mode 100644 index 00000000000..32022cc691d --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/inc/pr80755.h @@ -0,0 +1,2 @@ +#if __has_include_next() +#endif diff --git a/gcc/testsuite/gcc.dg/cpp/pr80755.c b/gcc/testsuite/gcc.dg/cpp/pr80755.c new file mode 100644 index 00000000000..34ae995a6c9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/pr80755.c @@ -0,0 +1,5 @@ +/* PR preprocessor/80755 */ +/* { dg-do preprocess } */ +/* { dg-options "-idirafter $srcdir/gcc.dg/cpp/inc" } */ + +#include "pr80755.h" diff --git a/libcpp/files.cc b/libcpp/files.cc index a18b1caf48d..606f53ed015 100644 --- a/libcpp/files.cc +++ b/libcpp/files.cc @@ -1042,7 +1042,7 @@ search_path_head (cpp_reader *pfile, const char *fname, int angle_brackets, path use the normal search logic. */ if (type == IT_INCLUDE_NEXT && file->dir && file->dir != &pfile->no_search_path) - dir = file->dir->next; + return file->dir->next; else if (angle_brackets) dir = pfile->bracket_include; else if (type == IT_CMDLINE) @@ -2145,6 +2145,8 @@ _cpp_has_header (cpp_reader *pfile, const char *fname, int angle_brackets, enum include_type type) { cpp_dir *start_dir = search_path_head (pfile, fname, angle_brackets, type); + if (!start_dir) + return false; _cpp_file *file = _cpp_find_file (pfile, fname, start_dir, angle_brackets, _cpp_FFK_HAS_INCLUDE, 0); return file->err_no != ENOENT;