public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: Bernd Schmidt <bschmidt@redhat.com>,
	       GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: Fix 69650, bogus line numbers from libcpp
Date: Fri, 11 Mar 2016 22:09:00 -0000	[thread overview]
Message-ID: <1457734166.5425.43.camel@redhat.com> (raw)
In-Reply-To: <56E132FC.2030404@redhat.com>

On Thu, 2016-03-10 at 09:40 +0100, Bernd Schmidt wrote:
> This is a case where bogus #line directives can confuse libcpp into 
> producing nonsensical line numbers, even leading to a crash later on
> in LTO.
> 
> The following patch moves the test earlier to a point where we can
> more 
> easily recover from the error condition. I should note that I changed
> the raw fprintf (stderr) to a cpp_error call, which is a slight
> change 
> in behaviour (we don't even get to LTO anymore due to erroring out
> earlier).
> 
> Bootstrapped and tested on x86_64-linux (as always including Ada,
> which 
> failed with an earlier version of the patch). Ok?

Thanks for looking at this.

> --- libcpp/directives.c	(revision 234025)
> +++ libcpp/directives.c	(working copy)
> @@ -1046,6 +1046,19 @@ do_linemarker (cpp_reader *pfile)
>  
>    skip_rest_of_line (pfile);
>  
> +  if (reason == LC_LEAVE)
> +    {
> +      const line_map_ordinary *from;      
> +      if (MAIN_FILE_P (map)
> +	  || (new_file
> +	      && (from = INCLUDED_FROM (pfile->line_table, map)) !=
NULL
> +	      && filename_cmp (ORDINARY_MAP_FILE_NAME (from),
new_file) != 0))
> +	{
> +	  cpp_error (pfile, CPP_DL_ERROR,
> +		     "file \"%s\" left but not entered", new_file);
                                                         ^^^^^^^^
Although it looks like you're preserving the existing behavior from
when this was in linemap_add, shouldn't this be
  ORDINARY_MAP_FILE_NAME (from)
rather than new_file?  (i.e. shouldn't it report the name of the file
being *left*, rather than the one being entered?)

[...]

> Index: gcc/testsuite/gcc.dg/pr69650.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/pr69650.c	(revision 0)
> +++ gcc/testsuite/gcc.dg/pr69650.c	(working copy)
> @@ -0,0 +1,5 @@
> +/* { dg-do compile } */
> +/* { dg-options "-std=gnu99" } */
> +
> +# 9 "" 2 /* { dg-error "left but not entered" } */
> +not_a_type a; /* { dg-error "unknown type" } */

Can we also have a testcase with a non-empty filename?  I'm interested
in seeing what the exact error messages looks like.

Also, is it possible to construct a testcase that triggers
the logic in the non-MAIN_FILE_P clause? (perhaps with some
# directives for a variety of "files")?


Hope this is constructive
Dave

  reply	other threads:[~2016-03-11 22:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <56E12FFF.6050800@t-online.de>
2016-03-10  8:40 ` Bernd Schmidt
2016-03-11 22:09   ` David Malcolm [this message]
2016-03-14 13:20     ` Bernd Schmidt
2016-03-21 14:58       ` Bernd Schmidt
2016-03-21 20:17       ` David Malcolm
2016-03-22  1:35         ` Bernd Schmidt
2016-03-23 12:58           ` Richard Biener
2016-03-23 13:21             ` Bernd Schmidt
2016-03-23 14:39               ` Richard Biener
2016-03-24 16:21                 ` Bernd Schmidt
2016-03-24 21:42                   ` Jeff Law
2016-03-25 18:25                     ` Jeff Law

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=1457734166.5425.43.camel@redhat.com \
    --to=dmalcolm@redhat.com \
    --cc=bschmidt@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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).