bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bison produces an output which causes gcc to hang


From: Akim Demaille
Subject: Re: bison produces an output which causes gcc to hang
Date: Mon, 22 Apr 2019 18:14:00 +0200

Hi Todd,

I will install the following patch so that Bison itself
does not suffer from the problem you reported about GCC.
But I leave the #line as they are, I am to be convinced
that Bison should not issue them for special files.

commit e98b6229d7f041f8e0b5f87cb719b326aa4495b6
Author: Akim Demaille <address@hidden>
Date:   Mon Apr 22 17:30:20 2019 +0200

    diagnostics: don't try to quote special files
    
    Based on a report by Todd Freed.
    http://lists.gnu.org/archive/html/bug-bison/2019-04/msg00000.html
    See also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90034
    
    * src/location.c (caret_info): Also track the file name.
    (location_caret): Don't quote special files.

diff --git a/THANKS b/THANKS
index 3a8baf3f..53a357ae 100644
--- a/THANKS
+++ b/THANKS
@@ -170,6 +170,7 @@ Tim Josling               address@hidden
 Tim Landscheidt           address@hidden
 Tim Van Holder            address@hidden
 Tobias Frost              address@hidden
+Todd Freed                address@hidden
 Tom Lane                  address@hidden
 Tom Tromey                address@hidden
 Tommy Nordgren            address@hidden
diff --git a/src/location.c b/src/location.c
index c5ec8569..6d361c19 100644
--- a/src/location.c
+++ b/src/location.c
@@ -23,6 +23,8 @@
 
 #include <mbswidth.h>
 #include <quotearg.h>
+#include <stdio.h>    /* fileno */
+#include <sys/stat.h> /* fstat */
 
 #include "complain.h"
 #include "location.h"
@@ -138,33 +140,63 @@ location_print (location loc, FILE *out)
 
 /* Persistent data used by location_caret to avoid reopening and rereading the
    same file all over for each error.  */
-struct caret_info
+static struct
 {
   FILE *source;
+  /* The last file we tried to open.  If non NULL, but SOURCE is NULL,
+     it means this file is special and should not be quoted. */
+  uniqstr file;
   size_t line;
   /* Offset in SOURCE where line LINE starts.  */
   size_t offset;
-};
-
-static struct caret_info caret_info = { NULL, 1, 0 };
+} caret_info;
 
 void
 caret_free ()
 {
   if (caret_info.source)
-    fclose (caret_info.source);
-  caret_info.source = NULL;
-  caret_info.line = 1;
-  caret_info.offset = 0;
+    {
+      fclose (caret_info.source);
+      caret_info.source = NULL;
+    }
 }
 
 void
 location_caret (location loc, const char *style, FILE *out)
 {
-  if (! (caret_info.source
-         || (caret_info.source = fopen (loc.start.file, "r")))
-      || loc.start.column == -1 || loc.start.line == -1)
+  if (loc.start.column == -1 || loc.start.line == -1)
     return;
+  /* If a different source than before, close and let the rest open
+     the new one. */
+  if (caret_info.file && caret_info.file != loc.start.file)
+    {
+      caret_free ();
+      caret_info.file = NULL;
+    }
+  if (!caret_info.file)
+    {
+      caret_info.file = loc.start.file;
+      if ((caret_info.source = fopen (caret_info.file, "r")))
+        {
+          /* If the file is not regular (imagine #line 1 "/dev/stdin"
+             in the input file for instance), don't try to quote the
+             source.  Keep caret_info.file set so that we don't try to
+             open it again, but leave caret_info.source NULL so that
+             we don't try to quote it. */
+          struct stat buf;
+          if (fstat (fileno (caret_info.source), &buf) == 0
+              && buf.st_mode & S_IFREG)
+            {
+              caret_info.line = 1;
+              caret_info.offset = 0;
+            }
+          else
+            caret_free ();
+        }
+    }
+  if (!caret_info.source)
+    return;
+
 
   /* If the line we want to quote is seekable (the same line as the previous
      location), just seek it. If it was a previous line, we lost track of it,
diff --git a/tests/diagnostics.at b/tests/diagnostics.at
index add313e0..8fc3aa66 100644
--- a/tests/diagnostics.at
+++ b/tests/diagnostics.at
@@ -161,5 +161,27 @@ input.y:18.4-17: <warning>warning:</warning> empty rule 
without %empty [<warning
 ]])
 
 
+## -------------- ##
+## Special files. ##
+## -------------- ##
+
+# Don't try to quote special files.
+# http://lists.gnu.org/archive/html/bug-bison/2019-04/msg00000.html
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90034
+
+AT_TEST([[Special files]],
+[[%%
+exp: a b
+a: {}
+#line 1 "/dev/stdout"
+b: {}
+]],
+[[input.y:11.4-5: <warning>warning:</warning> empty rule without %empty 
[<warning>-Wempty-rule</warning>]
+   11 | a: <warning>{}</warning>
+      |    <warning>^~</warning>
+/dev/stdout:1.4-5: <warning>warning:</warning> empty rule without %empty 
[<warning>-Wempty-rule</warning>]
+]])
+
+
 
 m4_popdef([AT_TEST])




reply via email to

[Prev in Thread] Current Thread [Next in Thread]