Hi!

This restores GCC 3.3 behavior on this testcase, before 3.4 started ICEing
on it when it started to use the common block comment skipping code for
-traditional-cpp and just a simple function for macro block comments has
been added.  Even the macro block comments can be not properly terminated
and we shouldn't crash on that, just diagnose it.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2018-01-30  Jakub Jelinek  <ja...@redhat.com>

        PR preprocessor/69869
        * traditional.c (skip_macro_block_comment): Return bool, true if
        the macro block comment is unterminated.
        (copy_comment): Use return value from skip_macro_block_comment instead
        of always false.

        * gcc.dg/cpp/trad/pr69869.c: New test.

--- libcpp/traditional.c.jj     2018-01-03 10:42:55.965763452 +0100
+++ libcpp/traditional.c        2018-01-30 17:31:00.251952284 +0100
@@ -120,7 +120,7 @@ check_output_buffer (cpp_reader *pfile,
 
 /* Skip a C-style block comment in a macro as a result of -CC.
    Buffer->cur points to the initial asterisk of the comment.  */
-static void
+static bool
 skip_macro_block_comment (cpp_reader *pfile)
 {
   const uchar *cur = pfile->buffer->cur;
@@ -131,10 +131,15 @@ skip_macro_block_comment (cpp_reader *pf
 
   /* People like decorating comments with '*', so check for '/'
      instead for efficiency.  */
-  while(! (*cur++ == '/' && cur[-2] == '*') )
-    ;
+  while (! (*cur++ == '/' && cur[-2] == '*'))
+    if (cur[-1] == '\n')
+      {
+       pfile->buffer->cur = cur - 1;
+       return true;
+      }
 
   pfile->buffer->cur = cur;
+  return false;
 }
 
 /* CUR points to the asterisk introducing a comment in the current
@@ -158,7 +163,7 @@ copy_comment (cpp_reader *pfile, const u
 
   buffer->cur = cur;
   if (pfile->context->prev)
-    unterminated = false, skip_macro_block_comment (pfile);
+    unterminated = skip_macro_block_comment (pfile);
   else
     unterminated = _cpp_skip_block_comment (pfile);
     
--- gcc/testsuite/gcc.dg/cpp/trad/pr69869.c.jj  2018-01-30 17:41:41.309544998 
+0100
+++ gcc/testsuite/gcc.dg/cpp/trad/pr69869.c     2018-01-30 17:45:06.783501149 
+0100
@@ -0,0 +1,8 @@
+/* PR preprocessor/69869 */
+/* { dg-do preprocess } */
+/* { dg-options "-traditional-cpp" } */
+
+#define C(a,b)a/**/b
+C (foo/,**/)
+C (foo/,*)
+/* { dg-error "-:unterminated comment" "" {target "*-*-*"} .-1 } */

        Jakub

Reply via email to