Blame SOURCES/gcc7-fortranlines.patch

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