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: 61650 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 C345A383A0FE for ; Wed, 7 Dec 2022 09:31:27 +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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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;