public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bernd Schmidt <bschmidt@redhat.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: David Malcolm <dmalcolm@redhat.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: Fix 69650, bogus line numbers from libcpp
Date: Thu, 24 Mar 2016 16:21:00 -0000	[thread overview]
Message-ID: <56F405DB.1060600@redhat.com> (raw)
In-Reply-To: <CAFiYyc1h5wsw7NwDCkFwGuesAsi8LdHvXMgQia3V-uNZ457Xuw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1504 bytes --]



On 03/23/2016 03:21 PM, Richard Biener wrote:
> On Wed, Mar 23, 2016 at 2:15 PM, Bernd Schmidt <bschmidt@redhat.com> wrote:
>> On 03/23/2016 01:41 PM, Richard Biener wrote:
>>>
>>> Btw, the issue in the PR is also fixed with a simple
>>>
>>> Index: libcpp/line-map.c
>>> ===================================================================
>>> --- libcpp/line-map.c   (revision 234415)
>>> +++ libcpp/line-map.c   (working copy)
>>> @@ -543,7 +543,7 @@ linemap_add (struct line_maps *set, enum
>>>                    to_file);
>>>
>>>          /* A TO_FILE of NULL is special - we use the natural values.  */
>>> -      if (error || to_file == NULL)
>>> +      if (to_file == NULL)
>>>           {
>>>             to_file = ORDINARY_MAP_FILE_NAME (from);
>>>             to_line = SOURCE_LINE (from, from[1].start_location);
>>
>>
>> I looked at that, but that made it hard to add the testcase as the line
>> numbers no longer match the dg-error directives. By moving this code we can
>> ignore the erroneous #line directive, and for this one testcase at least,
>> that makes the line numbers (and caret diagnostics etc.) come out right.
>
> After some more digging and looking at your patch I'd approve that if it would
> emit a warning rather than an error - so can you please adjust it?

Like this? No one has yet approved any better wording for the message, 
so given that you said "it's not a regression" I've left it, but I would 
now prefer "linemarker ignored due to incorrect nesting".


Bernd

[-- Attachment #2: cpp-leave.diff --]
[-- Type: text/x-patch, Size: 3463 bytes --]


	PR lto/69650
	* directives.c (do_linemarker): Test for file left but not entered
	here.
	* line-map.c (linemap_add): Not here.

	PR lto/69650
	* gcc.dg/pr69650.c: New test.

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 "somefile" 2 /* { dg-warning "left but not entered" } */
+not_a_type a; /* { dg-error "unknown type" } */
Index: libcpp/directives.c
===================================================================
--- libcpp/directives.c	(revision 234341)
+++ libcpp/directives.c	(working copy)
@@ -1046,6 +1046,19 @@
 
   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_warning (pfile, CPP_W_NONE,
+		     "file \"%s\" left but not entered", new_file);
+	  return;
+	}
+    }
   /* Compensate for the increment in linemap_add that occurs in
      _cpp_do_file_change.  We're currently at the start of the line
      *following* the #line directive.  A separate source_location for this
Index: libcpp/line-map.c
===================================================================
--- libcpp/line-map.c	(revision 234341)
+++ libcpp/line-map.c	(working copy)
@@ -512,43 +512,23 @@
 	 "included", this variable points the map in use right before the
 	 #include "included", inside the same "includer" file.  */
       line_map_ordinary *from;
-      bool error;
 
-      if (MAIN_FILE_P (map - 1))
-	{
-	  /* So this _should_ mean we are leaving the main file --
-	     effectively ending the compilation unit. But to_file not
-	     being NULL means the caller thinks we are leaving to
-	     another file. This is an erroneous behaviour but we'll
-	     try to recover from it. Let's pretend we are not leaving
-	     the main file.  */
-	  error = true;
-          reason = LC_RENAME;
-          from = map - 1;
-	}
-      else
-	{
-	  /* (MAP - 1) points to the map we are leaving. The
-	     map from which (MAP - 1) got included should be the map
-	     that comes right before MAP in the same file.  */
-	  from = INCLUDED_FROM (set, map - 1);
-	  error = to_file && filename_cmp (ORDINARY_MAP_FILE_NAME (from),
-					   to_file);
-	}
+      linemap_assert (!MAIN_FILE_P (map - 1));
+      /* (MAP - 1) points to the map we are leaving. The
+	 map from which (MAP - 1) got included should be the map
+	 that comes right before MAP in the same file.  */
+      from = INCLUDED_FROM (set, map - 1);
 
-      /* Depending upon whether we are handling preprocessed input or
-	 not, this can be a user error or an ICE.  */
-      if (error)
-	fprintf (stderr, "line-map.c: file \"%s\" left but not entered\n",
-		 to_file);
-
       /* A TO_FILE of NULL is special - we use the natural values.  */
-      if (error || to_file == NULL)
+      if (to_file == NULL)
 	{
 	  to_file = ORDINARY_MAP_FILE_NAME (from);
 	  to_line = SOURCE_LINE (from, from[1].start_location);
 	  sysp = ORDINARY_MAP_IN_SYSTEM_HEADER_P (from);
 	}
+      else
+	linemap_assert (filename_cmp (ORDINARY_MAP_FILE_NAME (from),
+				      to_file) == 0);
     }
 
   map->sysp = sysp;

  reply	other threads:[~2016-03-24 15:21 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
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 [this message]
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=56F405DB.1060600@redhat.com \
    --to=bschmidt@redhat.com \
    --cc=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.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).