Blame SOURCES/gcc8-fortranlines.patch

840d93
diff -Nrup a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c
840d93
--- a/gcc/fortran/scanner.c	2017-03-08 12:35:48.000000000 -0500
840d93
+++ b/gcc/fortran/scanner.c	2018-05-03 19:01:52.000000000 -0400
840d93
@@ -2097,6 +2097,10 @@ preprocessor_line (gfc_char_t *c)
840d93
           in the linemap.  Alternative could be using GC or updating linemap to
840d93
           point to the new name, but there is no API for that currently.  */
840d93
       current_file->filename = xstrdup (filename);
840d93
+
840d93
+      /* We need to tell the linemap API that the filename changed.  Just
840d93
+	 changing current_file is insufficient.  */
840d93
+      linemap_add (line_table, LC_RENAME, false, current_file->filename, line);
840d93
     }
840d93
 
840d93
   /* Set new line number.  */
840d93
diff -Nrup a/gcc/testsuite/gfortran.dg/linefile.f90 b/gcc/testsuite/gfortran.dg/linefile.f90
840d93
--- a/gcc/testsuite/gfortran.dg/linefile.f90	1969-12-31 19:00:00.000000000 -0500
840d93
+++ b/gcc/testsuite/gfortran.dg/linefile.f90	2018-05-07 13:34:22.000000000 -0400
840d93
@@ -0,0 +1,18 @@
840d93
+! { dg-do compile }
840d93
+! { dg-options "-Wall" }
840d93
+
840d93
+! This will verify that the # <line> <file> directive later does not
840d93
+! mess up the diagnostic on this line
840d93
+SUBROUTINE s(dummy) ! { dg-warning "Unused" }
840d93
+  INTEGER, INTENT(in) :: dummy
840d93
+END SUBROUTINE
840d93
+
840d93
+# 12345 "foo-f"
840d93
+SUBROUTINE s2(dummy)
840d93
+  INTEGER, INTENT(in) :: dummy
840d93
+END SUBROUTINE
840d93
+! We want to check that the # directive changes the filename in the
840d93
+! diagnostic.  Nothing else really matters here.  dg-regexp allows us
840d93
+! to see the entire diagnostic.  We just have to make sure to consume
840d93
+! the entire message.
840d93
+! { dg-regexp "foo-f\[^\n]*" }