> >>> 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 to document
> >>> this new behavior though (e.g. I actually don't know what this is
> >>> called in fortran...)
>
> I am not sure that -fmacro-prefix-map is the right name here.
> The file names recorded in the Fortran source file are not macros,
> so I think that -ffile-prefix-maps makes sense, -fmacro-prefix-map
> does not.

Yes, I kinda agree with that, hence the first version of the patch,
(reattached below)

The main "problem" I see with it is that there isn't a way to enable
this without also enabling debug map, which really doesn't matter for
me but I imagine someone might, given that there are two separate
options...

Also, I feel like it's also just a "bad" option name, it affects
`__builtin_FILE` which isn't a macro either. That said, I'm perfectly
fine with leaving the argument parsing as is, until someone with a
better sense about naming than me comes up with a new option name that
does file-prefix-map minus debug-prefix-map...

---------------------

 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 --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" } }
--
2.27.0

------------------------------

> Best regards
>
>         Thomas

Reply via email to