From 42dc1e149ee78eea7f4902900b5e2593b12d2d61 Mon Sep 17 00:00:00 2001 From: jakub Date: Wed, 31 Jan 2018 08:31:52 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@257220 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/gcc.dg/cpp/trad/pr69869.c | 8 ++++++++ libcpp/ChangeLog | 8 ++++++++ libcpp/traditional.c | 18 +++++++++++++----- 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/cpp/trad/pr69869.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 80cb48876e3..ed44f5601ef 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2018-01-31 Jakub Jelinek + PR preprocessor/69869 + * gcc.dg/cpp/trad/pr69869.c: New test. + PR c/84100 * gcc.dg/pr84100.c: New test. diff --git a/gcc/testsuite/gcc.dg/cpp/trad/pr69869.c b/gcc/testsuite/gcc.dg/cpp/trad/pr69869.c new file mode 100644 index 00000000000..aa7aa83547b --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/pr69869.c @@ -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 } */ diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index fdddd93f9ae..9c675a52d0c 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,11 @@ +2018-01-31 Jakub Jelinek + + 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. + 2018-01-27 Jakub Jelinek * include/cpplib.h (enum cpp_builtin_type): Change BT_LAST_USER from diff --git a/libcpp/traditional.c b/libcpp/traditional.c index e07c96b6343..b25d5222d8a 100644 --- a/libcpp/traditional.c +++ b/libcpp/traditional.c @@ -119,8 +119,11 @@ check_output_buffer (cpp_reader *pfile, size_t n) } /* 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 + PFILE->buffer->cur points to the initial asterisk of the comment, + change it to point to after the '*' and '/' characters that terminate it. + Return true if the macro has not been termined, in that case set + PFILE->buffer->cur to the end of the buffer. */ +static bool skip_macro_block_comment (cpp_reader *pfile) { const uchar *cur = pfile->buffer->cur; @@ -131,10 +134,15 @@ skip_macro_block_comment (cpp_reader *pfile) /* 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 +166,7 @@ copy_comment (cpp_reader *pfile, const uchar *cur, int in_define) 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); -- 2.11.4.GIT