Skip to content

Commit

Permalink
re PR preprocessor/17349 (// comments cause weird behaviour with opti…
Browse files Browse the repository at this point in the history
…ons -E -C)

2010-11-16  Kai Tietz  <[email protected]>

        PR preprocessor/17349
        * lex.c (save_comment): Handle in argument passing c++
        comments special.

2010-11-16  Kai Tietz  <[email protected]>

        PR preprocessor/17349
        * gcc.dg/cpp/cmdlne-C3.c: New.

From-SVN: r166817
  • Loading branch information
Kai Tietz authored and Kai Tietz committed Nov 16, 2010
1 parent 92cf739 commit 651a20b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
5 changes: 5 additions & 0 deletions gcc/testsuite/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2010-11-16 Kai Tietz <[email protected]>

PR preprocessor/17349
* gcc.dg/cpp/cmdlne-C3.c: New.

2010-11-16 Richard Guenther <[email protected]>

PR tree-optimization/44545
Expand Down
13 changes: 13 additions & 0 deletions gcc/testsuite/gcc.dg/cpp/cmdlne-C3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* { dg-do preprocess } */
/* { dg-options "-C -P" } */

#define macro(X) X

macro(
// Comment1
x
// Comment2
);

/* { dg-final { scan-file cmdlne-C3.i "\\\*\\\/ x \\\/\\\*" } } */

6 changes: 6 additions & 0 deletions libcpp/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2010-11-16 Kai Tietz <[email protected]>

PR preprocessor/17349
* lex.c (save_comment): Handle in argument passing c++
comments special.

2010-11-02 Ian Lance Taylor <[email protected]>

* configure.ac: Use AC_SYS_LARGEFILE.
Expand Down
18 changes: 12 additions & 6 deletions libcpp/lex.c
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ save_comment (cpp_reader *pfile, cpp_token *token, const unsigned char *from,
cppchar_t type)
{
unsigned char *buffer;
unsigned int len, clen;
unsigned int len, clen, i;

len = pfile->buffer->cur - from + 1; /* + 1 for the initial '/'. */

Expand All @@ -1650,13 +1650,14 @@ save_comment (cpp_reader *pfile, cpp_token *token, const unsigned char *from,
if (is_vspace (pfile->buffer->cur[-1]))
len--;

/* If we are currently in a directive, then we need to store all
C++ comments as C comments internally, and so we need to
allocate a little extra space in that case.
/* If we are currently in a directive or in argument parsing, then
we need to store all C++ comments as C comments internally, and
so we need to allocate a little extra space in that case.
Note that the only time we encounter a directive here is
when we are saving comments in a "#define". */
clen = (pfile->state.in_directive && type == '/') ? len + 2 : len;
clen = ((pfile->state.in_directive || pfile->state.parsing_args)
&& type == '/') ? len + 2 : len;

buffer = _cpp_unaligned_alloc (pfile, clen);

Expand All @@ -1668,11 +1669,16 @@ save_comment (cpp_reader *pfile, cpp_token *token, const unsigned char *from,
memcpy (buffer + 1, from, len - 1);

/* Finish conversion to a C comment, if necessary. */
if (pfile->state.in_directive && type == '/')
if ((pfile->state.in_directive || pfile->state.parsing_args) && type == '/')
{
buffer[1] = '*';
buffer[clen - 2] = '*';
buffer[clen - 1] = '/';
/* As there can be in a C++ comments illegal sequences for C comments
we need to filter them out. */
for (i = 2; i < (clen - 2); i++)
if (buffer[i] == '/' && (buffer[i - 1] == '*' || buffer[i + 1] == '*'))
buffer[i] = '|';
}

/* Finally store this comment for use by clients of libcpp. */
Expand Down

0 comments on commit 651a20b

Please sign in to comment.