* [PATCH] Fix -traditional-cpp preprocessing ICE (PR preprocessor/69869)
@ 2018-01-30 23:25 Jakub Jelinek
2018-01-31 5:35 ` Joseph Myers
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2018-01-30 23:25 UTC (permalink / raw)
To: Tom Tromey, Joseph S. Myers, Marek Polacek, Jason Merrill,
Nathan Sidwell
Cc: gcc-patches
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 <jakub@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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix -traditional-cpp preprocessing ICE (PR preprocessor/69869)
2018-01-30 23:25 [PATCH] Fix -traditional-cpp preprocessing ICE (PR preprocessor/69869) Jakub Jelinek
@ 2018-01-31 5:35 ` Joseph Myers
0 siblings, 0 replies; 2+ messages in thread
From: Joseph Myers @ 2018-01-31 5:35 UTC (permalink / raw)
To: Jakub Jelinek
Cc: Tom Tromey, Marek Polacek, Jason Merrill, Nathan Sidwell, gcc-patches
On Tue, 30 Jan 2018, Jakub Jelinek wrote:
> 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?
OK with the comment on skip_macro_block_comment updated to document the
semantics of the return value.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-01-31 0:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-30 23:25 [PATCH] Fix -traditional-cpp preprocessing ICE (PR preprocessor/69869) Jakub Jelinek
2018-01-31 5:35 ` Joseph Myers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).