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