From: Jeff Law Date: Mon, 7 May 2018 18:24:59 +0000 (-0600) Subject: scanner.c (preprocessor_line): Call linemap_add after a line directive that changes... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0d1f4de97d9b51e04f6678448fb7c796a8fba6b1;p=gcc.git scanner.c (preprocessor_line): Call linemap_add after a line directive that changes the current filename. * 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 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index b94feb987fa..3735dc6a961 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2018-05-07 Jeff Law + + * scanner.c (preprocessor_line): Call linemap_add after a line + directive that changes the current filename. + 2018-05-06 Andre Vehreschild PR fortran/85507 diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c index aab53797de2..55d6dafdb5d 100644 --- a/gcc/fortran/scanner.c +++ b/gcc/fortran/scanner.c @@ -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. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 652192b0eba..e8b417ad29e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-05-07 Jeff Law + + * gfortran.dg/linefile.f90: New test. + 2018-05-07 Christophe Lyon * 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 index 00000000000..8e1366b0802 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/linefile.f90 @@ -0,0 +1,18 @@ +! { dg-do compile } +! { dg-options "-Wall" } + +! This will verify that the # 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]*" }