summaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-02-04 13:38:16 +0100
committerJakub Jelinek <jakub@redhat.com>2020-02-04 13:38:16 +0100
commitc04babd9dfa5c63c10d65f1bd3fb8cf503ab739d (patch)
tree27ca4c4c576f923bbe3abd73dd0f7d8ae70f5720 /gcc/testsuite/c-c++-common
parent5bc9d2f5ed4c39a7cad74db34e2bb125e012fa60 (diff)
libcpp: Fix ICEs on __has_include syntax errors [PR93545]
Some of the following testcases ICE, because one of the cpp_get_token calls in builtin_has_include reads the CPP_EOF token but the caller isn't aware that CPP_EOF has been reached and will do another cpp_get_token. get_token_no_padding is something that is use by the has_attribute/has_builtin callbacks, which will first peek and will not consume CPP_EOF (but will consume other tokens). The !SEEN_EOL () check on the other side doesn't work anymore and isn't really needed, as we don't consume the EOF. The change adds one further error to the pr88974.c testcase, if we wanted just one error per __has_include, we could add some boolean whether we've emitted errors already and only emit the first one we encounter (not implemented). 2020-02-04 Jakub Jelinek <jakub@redhat.com> PR preprocessor/93545 * macro.c (cpp_get_token_no_padding): New function. (builtin_has_include): Use it instead of cpp_get_token. Don't check SEEN_EOL. * c-c++-common/cpp/pr88974.c: Expect another diagnostics during error recovery. * c-c++-common/cpp/pr93545-1.c: New test. * c-c++-common/cpp/pr93545-2.c: New test. * c-c++-common/cpp/pr93545-3.c: New test. * c-c++-common/cpp/pr93545-4.c: New test.
Diffstat (limited to 'gcc/testsuite/c-c++-common')
-rw-r--r--gcc/testsuite/c-c++-common/cpp/pr88974.c1
-rw-r--r--gcc/testsuite/c-c++-common/cpp/pr93545-1.c4
-rw-r--r--gcc/testsuite/c-c++-common/cpp/pr93545-2.c4
-rw-r--r--gcc/testsuite/c-c++-common/cpp/pr93545-3.c4
-rw-r--r--gcc/testsuite/c-c++-common/cpp/pr93545-4.c4
5 files changed, 17 insertions, 0 deletions
diff --git a/gcc/testsuite/c-c++-common/cpp/pr88974.c b/gcc/testsuite/c-c++-common/cpp/pr88974.c
index c375d83c75f..d6c2414ea1f 100644
--- a/gcc/testsuite/c-c++-common/cpp/pr88974.c
+++ b/gcc/testsuite/c-c++-common/cpp/pr88974.c
@@ -3,4 +3,5 @@
#if __has_include (<pr88974.h)
/* { dg-error "missing terminating > character" "" { target *-*-* } .-1 } */
+/* { dg-error "missing '\\\)' after .__has_include. operand" "" { target *-*-* } .-2 } */
#endif
diff --git a/gcc/testsuite/c-c++-common/cpp/pr93545-1.c b/gcc/testsuite/c-c++-common/cpp/pr93545-1.c
new file mode 100644
index 00000000000..757277b7135
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/pr93545-1.c
@@ -0,0 +1,4 @@
+/* PR preprocessor/93545 */
+/* { dg-do preprocess } */
+
+__has_include /* { dg-error "" } */
diff --git a/gcc/testsuite/c-c++-common/cpp/pr93545-2.c b/gcc/testsuite/c-c++-common/cpp/pr93545-2.c
new file mode 100644
index 00000000000..5ed2dab47ec
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/pr93545-2.c
@@ -0,0 +1,4 @@
+/* PR preprocessor/93545 */
+/* { dg-do preprocess } */
+
+__has_include ( /* { dg-error "" } */
diff --git a/gcc/testsuite/c-c++-common/cpp/pr93545-3.c b/gcc/testsuite/c-c++-common/cpp/pr93545-3.c
new file mode 100644
index 00000000000..eae13bddfaa
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/pr93545-3.c
@@ -0,0 +1,4 @@
+/* PR preprocessor/93545 */
+/* { dg-do preprocess } */
+
+__has_include ("foobarbaz" /* { dg-error "" } */
diff --git a/gcc/testsuite/c-c++-common/cpp/pr93545-4.c b/gcc/testsuite/c-c++-common/cpp/pr93545-4.c
new file mode 100644
index 00000000000..977d210ac76
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/pr93545-4.c
@@ -0,0 +1,4 @@
+/* PR preprocessor/93545 */
+/* { dg-do preprocess } */
+
+__has_include () /* { dg-error "" } */