diff mbox series

Map filename from print in gfortran with -ffile-prefix-map (PR96069)

Message ID CAMvDr+QsUkQTN=krytb2kf_meyhyeWrY3tx1SU4YgEx2kRzkLg@mail.gmail.com
State New
Headers show
Series Map filename from print in gfortran with -ffile-prefix-map (PR96069) | expand

Commit Message

Yichao Yu July 6, 2020, 12:45 a.m. UTC
Currently this is using the macro prefix map without allowing the
---fmacro-prefix-map argument, which is arguably pretty weird... but I
don't know what would be a better way.

I think this remapping should happen with `file-prefix-map` but shouldn't
with `debug-prefix-map` (though if it happens for both it's also not too
bad) and I believe this patch is the minimum change to achieve that. I
think it makes sense to make this follow `macro-prefix-map` although I'm
not sure if this is a macro... (OTOH, __builtin_FILE isn't a macro either
so maybe it's fine?). I haven't figured out how I can allow the option in
gfortran or how do document this new behavior though (e.g. I actually don't
know what this is called in fortran...)

---
gcc/fortran/trans-io.c                |  3 ++-
gcc/testsuite/gfortran.dg/pr96069.f90 | 11 +++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gfortran.dg/pr96069.f90
diff mbox series

Patch

diff --git a/gcc/fortran/trans-io.c b/gcc/fortran/trans-io.c
index 21bdd5ef0d8..4d406493603 100644
--- a/gcc/fortran/trans-io.c
+++ b/gcc/fortran/trans-io.c
@@ -33,6 +33,7 @@  along with GCC; see the file COPYING3.  If not see
#include "trans-types.h"
#include "trans-const.h"
#include "options.h"
+#include "file-prefix-map.h" /* remap_macro_filename()  */

/* Members of the ioparm structure.  */

@@ -1026,7 +1027,7 @@  set_error_locus (stmtblock_t * block, tree var, locus
* where)
                               TREE_TYPE (p->field), locus_file,
                               p->field, NULL_TREE);
  f = where->lb->file;
-  str = gfc_build_cstring_const (f->filename);
+  str = gfc_build_cstring_const (remap_macro_filename(f->filename));

  str = gfc_build_addr_expr (pchar_type_node, str);
  gfc_add_modify (block, locus_file, str);
diff --git a/gcc/testsuite/gfortran.dg/pr96069.f90
b/gcc/testsuite/gfortran.dg/pr96069.f90
new file mode 100644
index 00000000000..de8bd3a14de
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr96069.f90
@@ -0,0 +1,11 @@ 
+! { dg-do compile }
+! { dg-options "-ffile-prefix-map==MACRO-PREFIX" }
+
+subroutine f(name)
+  implicit none
+  character*(*) name
+  print *,name
+  return
+end subroutine f
+
+! { dg-final { scan-assembler ".string\t\"MACRO-PREFIX" } }