scanner.c (preprocessor_line): Call linemap_add after a line directive that changes...
authorJeff Law <law@gcc.gnu.org>
Mon, 7 May 2018 18:24:59 +0000 (12:24 -0600)
committerJeff Law <law@gcc.gnu.org>
Mon, 7 May 2018 18:24:59 +0000 (12:24 -0600)
* scanner.c (preprocessor_line): Call linemap_add after a line
directive that changes the current filename.

* gfortran.dg/linefile.f90: New test.

From-SVN: r260010

gcc/fortran/ChangeLog
gcc/fortran/scanner.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/linefile.f90 [new file with mode: 0644]

index b94feb987fa168c87c5b391c4dd6692db0a21210..3735dc6a961633fbb041c2dd79bc019acfef9fba 100644 (file)
@@ -1,3 +1,8 @@
+2018-05-07  Jeff Law  <law@redhat.comg>
+
+       * scanner.c (preprocessor_line): Call linemap_add after a line
+       directive that changes the current filename.
+
 2018-05-06  Andre Vehreschild  <vehre@gcc.gnu.org>
 
        PR fortran/85507
index aab53797de27010446812a6ccc8a1b80b3356270..55d6dafdb5dd46d68f28da929ace3939d070e97d 100644 (file)
@@ -2107,6 +2107,10 @@ preprocessor_line (gfc_char_t *c)
           in the linemap.  Alternative could be using GC or updating linemap to
           point to the new name, but there is no API for that currently.  */
       current_file->filename = xstrdup (filename);
+
+      /* We need to tell the linemap API that the filename changed.  Just
+        changing current_file is insufficient.  */
+      linemap_add (line_table, LC_RENAME, false, current_file->filename, line);
     }
 
   /* Set new line number.  */
index 652192b0eba1cc5b850822f0e6269c7d7390e598..e8b417ad29ebcf6b98bd3c4c492b1db9b44ca032 100644 (file)
@@ -1,3 +1,7 @@
+2018-05-07  Jeff Law  <law@redhat.com>
+
+       * gfortran.dg/linefile.f90: New test.
+
 2018-05-07  Christophe Lyon  <christophe.lyon@linaro.org>
 
        * gcc.dg/nextafter-2.c: Add c99_runtime effective target
diff --git a/gcc/testsuite/gfortran.dg/linefile.f90 b/gcc/testsuite/gfortran.dg/linefile.f90
new file mode 100644 (file)
index 0000000..8e1366b
--- /dev/null
@@ -0,0 +1,18 @@
+! { dg-do compile }
+! { dg-options "-Wall" }
+
+! This will verify that the # <line> <file> directive later does not
+! mess up the diagnostic on this line
+SUBROUTINE s(dummy) ! { dg-warning "Unused" }
+  INTEGER, INTENT(in) :: dummy
+END SUBROUTINE
+
+# 12345 "foo-f"
+SUBROUTINE s2(dummy)
+  INTEGER, INTENT(in) :: dummy
+END SUBROUTINE
+! We want to check that the # directive changes the filename in the
+! diagnostic.  Nothing else really matters here.  dg-regexp allows us
+! to see the entire diagnostic.  We just have to make sure to consume
+! the entire message.
+! { dg-regexp "foo-f\[^\n]*" }