This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PR debug/67192] Fix C loops' back-jump location
- From: Andreas Arnez <arnez at linux dot vnet dot ibm dot com>
- To: Bernd Schmidt <bschmidt at redhat dot com>
- Cc: Joseph Myers <joseph at codesourcery dot com>, Richard Henderson <rth at redhat dot com>, gcc-patches at gcc dot gnu dot org, David Malcolm <dmalcolm at redhat dot com>, Manuel LÃpez-IbÃÃez <lopezibanez at gmail dot com>, Patrick Palka <patrick at parcs dot ath dot cx>, Andreas Krebbel <krebbel at linux dot vnet dot ibm dot com>
- Date: Fri, 23 Oct 2015 11:07:23 +0200
- Subject: Re: [PR debug/67192] Fix C loops' back-jump location
- Authentication-results: sourceware.org; auth=none
- References: <m3si5gji8n dot fsf at oc1027705133 dot ibm dot com> <561CFB09 dot 5030903 at redhat dot com>
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.