aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Booth <neil@daikokuya.demon.co.uk>2002-04-21 16:17:55 +0000
committerNeil Booth <neil@gcc.gnu.org>2002-04-21 16:17:55 +0000
commit9ac3b1bec7b58c6ad4a76782b1116dfb5f4cd0c6 (patch)
tree249f1d8f5adab5ad3e3c0bdc851bb1799c3102f2
parentd8b85ae5975987fbac892ed4350d860b3abef533 (diff)
downloadgcc-9ac3b1bec7b58c6ad4a76782b1116dfb5f4cd0c6.zip
gcc-9ac3b1bec7b58c6ad4a76782b1116dfb5f4cd0c6.tar.gz
gcc-9ac3b1bec7b58c6ad4a76782b1116dfb5f4cd0c6.tar.bz2
cppmacro.c (funlike_invocation_p): Don't step back over CPP_EOF.
* cppmacro.c (funlike_invocation_p): Don't step back over CPP_EOF. testsuite: * gcc.dg/cpp/endif.h, gcc.dg/cpp/endif.c: New tests. From-SVN: r52586
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/cppmacro.c17
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/cpp/endif.c14
-rw-r--r--gcc/testsuite/gcc.dg/cpp/endif.h1
5 files changed, 35 insertions, 6 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index db431d1..f7a6c68 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2002-04-21 Neil Booth <neil@daikokuya.demon.co.uk>
+
+ * cppmacro.c (funlike_invocation_p): Don't step back
+ over CPP_EOF.
+
2002-04-21 David Edelsohn <edelsohn@gnu.org>
* config/rs6000/rs6000.c (output_profile_hook): Do not increment
diff --git a/gcc/cppmacro.c b/gcc/cppmacro.c
index 2070851..d39bd45 100644
--- a/gcc/cppmacro.c
+++ b/gcc/cppmacro.c
@@ -632,12 +632,17 @@ funlike_invocation_p (pfile, node)
return collect_args (pfile, node);
}
- /* Back up. We may have skipped padding, in which case backing up
- more than one token when expanding macros is in general too
- difficult. We re-insert it in its own context. */
- _cpp_backup_tokens (pfile, 1);
- if (padding)
- push_token_context (pfile, NULL, padding, 1);
+ /* CPP_EOF can be the end of macro arguments, or the end of the
+ file. We mustn't back up over the latter. Ugh. */
+ if (token->type != CPP_EOF || token == &pfile->eof)
+ {
+ /* Back up. We may have skipped padding, in which case backing
+ up more than one token when expanding macros is in general
+ too difficult. We re-insert it in its own context. */
+ _cpp_backup_tokens (pfile, 1);
+ if (padding)
+ push_token_context (pfile, NULL, padding, 1);
+ }
return NULL;
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 2d2c534..8c5385f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2002-04-21 Neil Booth <neil@daikokuya.demon.co.uk>
+
+ * gcc.dg/cpp/endif.h, gcc.dg/cpp/endif.c: New tests.
+
2002-04-21 Franz Sirl <Franz.Sirl-kernel@lauterbach.com>
* gcc.c-torture/execute/20000906-1.x: Delete.
diff --git a/gcc/testsuite/gcc.dg/cpp/endif.c b/gcc/testsuite/gcc.dg/cpp/endif.c
new file mode 100644
index 0000000..efea52c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/endif.c
@@ -0,0 +1,14 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc. */
+
+/* { dg-do preprocess } */
+
+/* Test case for PR preprocessor/6386 by Andreas Schwab. We'd back up
+ over the CPP_EOF token (indicating not a funlike macro invocation)
+ in the header file, which would then be passed through as a real
+ EOF, leading to an early exit (and therefore bogus complaint about
+ unterminated #if). */
+
+#define S(x)
+#if 1
+#include "endif.h"
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/endif.h b/gcc/testsuite/gcc.dg/cpp/endif.h
new file mode 100644
index 0000000..3762249
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/endif.h
@@ -0,0 +1 @@
+S