diff options
author | Lewis Hyatt <lhyatt@gmail.com> | 2023-09-15 13:31:51 -0400 |
---|---|---|
committer | Lewis Hyatt <lhyatt@gmail.com> | 2023-09-20 16:44:24 -0400 |
commit | 601dbf2a799f691688dfe78250b5bea2717b5b5e (patch) | |
tree | b5309aa08914667b85299fe105b7c5881910a495 /gcc/testsuite/c-c++-common/cpp | |
parent | b512d705797a65dbfe3a9ad100218192c7528b02 (diff) | |
download | gcc-601dbf2a799f691688dfe78250b5bea2717b5b5e.zip gcc-601dbf2a799f691688dfe78250b5bea2717b5b5e.tar.gz gcc-601dbf2a799f691688dfe78250b5bea2717b5b5e.tar.bz2 |
libcpp: Fix ICE on #include after a line marker directive [PR61474]
As noted in the PR, GCC will segfault if a file name is first seen in a
linemarker directive, and then later seen in a normal #include. This is
because the fake include process adds the file to the cache with a null PATH
member. The normal #include finds this file in the cache and then attempts
to use the null PATH. Resolve by adding the file to the cache with a unique
starting directory, so that the fake entry will only be found by a
subsequent fake include, not by a real one.
libcpp/ChangeLog:
PR preprocessor/61474
* files.cc (_cpp_find_file): Set DONT_READ to TRUE for fake
include files.
(_cpp_fake_include): Pass a unique cpp_dir* address so
the fake file will not be found when looked up for real.
gcc/testsuite/ChangeLog:
PR preprocessor/61474
* c-c++-common/cpp/pr61474-2.h: New test.
* c-c++-common/cpp/pr61474.c: New test.
* c-c++-common/cpp/pr61474.h: New test.
Diffstat (limited to 'gcc/testsuite/c-c++-common/cpp')
-rw-r--r-- | gcc/testsuite/c-c++-common/cpp/pr61474-2.h | 1 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/cpp/pr61474.c | 5 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/cpp/pr61474.h | 6 |
3 files changed, 12 insertions, 0 deletions
diff --git a/gcc/testsuite/c-c++-common/cpp/pr61474-2.h b/gcc/testsuite/c-c++-common/cpp/pr61474-2.h new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/pr61474-2.h @@ -0,0 +1 @@ +#pragma once diff --git a/gcc/testsuite/c-c++-common/cpp/pr61474.c b/gcc/testsuite/c-c++-common/cpp/pr61474.c new file mode 100644 index 0000000..f835a40 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/pr61474.c @@ -0,0 +1,5 @@ +/* { dg-do preprocess } */ +#include "pr61474.h" +/* Make sure that the file can be included for real, after it was + fake-included by the linemarker directives in pr61474.h. */ +#include "pr61474-2.h" diff --git a/gcc/testsuite/c-c++-common/cpp/pr61474.h b/gcc/testsuite/c-c++-common/cpp/pr61474.h new file mode 100644 index 0000000..d9e8c3a --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/pr61474.h @@ -0,0 +1,6 @@ +/* Create a fake include for pr61474-2.h and exercise looking it up. */ +/* Use #pragma once to check also that the fake-include entry in the file + cache does not cause a problem in libcpp/files.cc:has_unique_contents(). */ +#pragma once +# 1 "pr61474-2.h" 1 +# 2 "pr61474-2.h" 1 |