On Tue, Oct 13 2015, Bernd Schmidt wrote:

> One could argue that peek_token should not have an effect on
> input_location, and in fact cpp_peek_token seems to take steps that
> this does not happen, but it looks like c_parser_peek_token does not
> use that mechanism.

Yes, the C/C++ parsers differ quite significantly in this regard.  The C
parser invokes the lexer in peek_token and advances input_location upon
each newline.  The C++ parser usually lexes everything in advance and
updates input_location on each *consumed* token.

By advancing input_location in peek_token upon each newline, diagnostics
emitted with warning() and friends point to the beginning of the line of
the peeked-at token.  This is probably somewhat intended, so I'd rather
not touch that right now.

A different aspect is the implicit use of input_location for the
location of generated statements.  This usage is what causes the problem
at hand, and IMHO it should generally be rooted out.

>> Still,
>>
>> gcc/testsuite/ChangeLog:
>>
>>      PR debug/67192
>>      * gcc.dg/guality/pr67192.c: New test.
>>
>> gcc/c/ChangeLog:
>>
>>      PR debug/67192
>>      * c-parser.c (c_parser_while_statement): Finish the loop before
>>      parsing ahead for misleading indentation.
>>      (c_parser_for_statement): Likewise.
>
> This fix looks simple enough. Ok. (Might want to add noclone to the
> testcase attributes).

Thanks for reviewing!  Unfortunately, after investigating this some
more, I realized that my solution is incomplete.  E.g., consider this:

  while (1)
    if (foo ())
       break;
    else
       do_something ();
  bar ();      /* break here */

Interestingly, line number information for such code has been broken in
GCC for a long time.

I'll send an updated version.

Reply via email to