public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] preprocessor: __has_include_next should not error out [PR80755]
@ 2022-12-07  9:30 Helmut Grohne
  0 siblings, 0 replies; only message in thread
From: Helmut Grohne @ 2022-12-07  9:30 UTC (permalink / raw)
  To: 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 <helmut@subdivi.de>
---
 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(<itdoesnotmatterwhetherthisheaderexists>)
+#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;
-- 
2.38.1



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-07  9:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-07  9:30 [PATCH] preprocessor: __has_include_next should not error out [PR80755] Helmut Grohne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).