public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andreas Arnez <arnez@linux.vnet.ibm.com>
To: Bernd Schmidt <bschmidt@redhat.com>
Cc: "Joseph Myers" <joseph@codesourcery.com>,
	"Richard Henderson" <rth@redhat.com>,
	gcc-patches@gcc.gnu.org, "David Malcolm" <dmalcolm@redhat.com>,
	"Manuel López-Ibáñez" <lopezibanez@gmail.com>,
	"Patrick Palka" <patrick@parcs.ath.cx>,
	"Andreas Krebbel" <krebbel@linux.vnet.ibm.com>
Subject: Re: [PR debug/67192] Fix C loops' back-jump location
Date: Fri, 23 Oct 2015 09:10:00 -0000	[thread overview]
Message-ID: <m3611yrm0k.fsf@oc1027705133.ibm.com> (raw)
In-Reply-To: <561CFB09.5030903@redhat.com> (Bernd Schmidt's message of "Tue,	13 Oct 2015 14:37:29 +0200")

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	other threads:[~2015-10-23  9:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-12 14:04 Andreas Arnez
2015-10-13 12:37 ` Bernd Schmidt
2015-10-23  9:10   ` Andreas Arnez [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3611yrm0k.fsf@oc1027705133.ibm.com \
    --to=arnez@linux.vnet.ibm.com \
    --cc=bschmidt@redhat.com \
    --cc=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    --cc=krebbel@linux.vnet.ibm.com \
    --cc=lopezibanez@gmail.com \
    --cc=patrick@parcs.ath.cx \
    --cc=rth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).