aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorLewis Hyatt <lhyatt@gmail.com>2023-12-20 16:27:42 -0500
committerLewis Hyatt <lhyatt@gmail.com>2024-03-14 07:33:02 -0400
commit6c166e55b15894ceb07dcc7b55f900e50e24ec5b (patch)
treebaad9623de6445515e183e7d243b2436295037f7 /gcc
parentb7f70cfdb6f7ab369ecca14a99a0064d2a11ddd2 (diff)
downloadgcc-6c166e55b15894ceb07dcc7b55f900e50e24ec5b.zip
gcc-6c166e55b15894ceb07dcc7b55f900e50e24ec5b.tar.gz
gcc-6c166e55b15894ceb07dcc7b55f900e50e24ec5b.tar.bz2
libcpp: Fix __has_include_next ICE in the last directory of the path [PR80755]
In libcpp/files.cc, the function _cpp_has_header(), which implements __has_include and __has_include_next, does not check for a NULL return value from search_path_head(), leading to an ICE tripping an assert when _cpp_find_file() tries to use it. Fix it by checking for that case and silently returning false instead. As suggested by the PR author, it is easiest to make a testcase by using the -idirafter option. To enable that, also modify the dg-additional-options testsuite procedure to make the global $srcdir available, since -idirafter requires the full path. libcpp/ChangeLog: PR preprocessor/80755 * files.cc (search_path_head): Add SUPPRESS_DIAGNOSTIC argument defaulting to false. (_cpp_has_header): Silently return false if the search path has been exhausted, rather than issuing a diagnostic and then hitting an assert. gcc/testsuite/ChangeLog: * lib/gcc-defs.exp (dg-additional-options): Make $srcdir usable in a dg-additional-options directive. * c-c++-common/cpp/has-include-next-2-dir/has-include-next-2.h: New test. * c-c++-common/cpp/has-include-next-2.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/c-c++-common/cpp/has-include-next-2-dir/has-include-next-2.h3
-rw-r--r--gcc/testsuite/c-c++-common/cpp/has-include-next-2.c4
-rw-r--r--gcc/testsuite/lib/gcc-defs.exp1
3 files changed, 8 insertions, 0 deletions
diff --git a/gcc/testsuite/c-c++-common/cpp/has-include-next-2-dir/has-include-next-2.h b/gcc/testsuite/c-c++-common/cpp/has-include-next-2-dir/has-include-next-2.h
new file mode 100644
index 0000000..1e4be6c
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/has-include-next-2-dir/has-include-next-2.h
@@ -0,0 +1,3 @@
+#if __has_include_next(<whatever>)
+/* This formerly led to an ICE when the current directory was the last one in the path. */
+#endif
diff --git a/gcc/testsuite/c-c++-common/cpp/has-include-next-2.c b/gcc/testsuite/c-c++-common/cpp/has-include-next-2.c
new file mode 100644
index 0000000..4928d3e
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/has-include-next-2.c
@@ -0,0 +1,4 @@
+/* PR preprocessor/80755 */
+/* { dg-do preprocess } */
+/* { dg-additional-options "-idirafter $srcdir/c-c++-common/cpp/has-include-next-2-dir" } */
+#include <has-include-next-2.h>
diff --git a/gcc/testsuite/lib/gcc-defs.exp b/gcc/testsuite/lib/gcc-defs.exp
index 56851f4..70215ed 100644
--- a/gcc/testsuite/lib/gcc-defs.exp
+++ b/gcc/testsuite/lib/gcc-defs.exp
@@ -280,6 +280,7 @@ if { [info exists env(GCC_RUNTEST_PARALLELIZE_DIR)] \
proc dg-additional-options { args } {
upvar dg-extra-tool-flags extra-tool-flags
+ global srcdir
if { [llength $args] > 3 } {
error "[lindex $args 0]: too many arguments"