> > > 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...)

Any comments?

> >
> > And here's a version that makes -fmacro-prefix-remap a common option.
> >
> > ---
> > diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
> > index 9b6300f330f..6d105e24f16 100644
> > --- a/gcc/c-family/c-opts.c
> > +++ b/gcc/c-family/c-opts.c
> > @@ -40,7 +40,6 @@ along with GCC; see the file COPYING3.  If not see
> > #include "plugin.h"            /* For PLUGIN_INCLUDE_FILE event.  */
> > #include "mkdeps.h"
> > #include "dumpfile.h"
> > -#include "file-prefix-map.h"    /* add_*_prefix_map()  */
> >
> > #ifndef DOLLARS_IN_IDENTIFIERS
> > # define DOLLARS_IN_IDENTIFIERS true
> > @@ -443,10 +442,6 @@ c_common_handle_option (size_t scode, const char
> > *arg, HOST_WIDE_INT value
> > ,
> >       cpp_opts->dollars_in_ident = value;
> >       break;
> >
> > -    case OPT_fmacro_prefix_map_:
> > -      add_macro_prefix_map (arg);
> > -      break;
> > -
> >     case OPT_ffreestanding:
> >       value = !value;
> >       /* Fall through.  */
> > diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
> > index 89a58282b3f..bf9899d1aef 100644
> > --- a/gcc/c-family/c.opt
> > +++ b/gcc/c-family/c.opt
> > @@ -1517,10 +1517,6 @@ fdollars-in-identifiers
> > C ObjC C++ ObjC++
> > Permit '$' as an identifier character.
> >
> > -fmacro-prefix-map=
> > -C ObjC C++ ObjC++ Joined RejectNegative
> > --fmacro-prefix-map=<old>=<new> Map one directory name to another in
> > __FILE__, __BASE_FILE__, a
> > nd __builtin_FILE().
> > -
> > fdump-ada-spec
> > C ObjC C++ ObjC++ RejectNegative Var(flag_dump_ada_spec)
> > Write all declarations as Ada code transitively.
> > diff --git a/gcc/common.opt b/gcc/common.opt
> > index df8af365d1b..e018716af89 100644
> > --- a/gcc/common.opt
> > +++ b/gcc/common.opt
> > @@ -1217,6 +1217,10 @@ fdebug-prefix-map=
> > Common Joined RejectNegative Var(common_deferred_options) Defer
> > -fdebug-prefix-map=<old>=<new> Map one directory name to another in
> > debug information.
> >
> > +fmacro-prefix-map=
> > +Common Joined RejectNegative Var(common_deferred_options) Defer
> > +-fmacro-prefix-map=<old>=<new> Map one directory name to another in
> > __FILE__, __BASE_FILE__, a
> > nd __builtin_FILE().
> > +
> > ffile-prefix-map=
> > Common Joined RejectNegative Var(common_deferred_options) Defer
> > -ffile-prefix-map=<old>=<new>  Map one directory name to another in
> > compilation result.
> > 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/opts-global.c b/gcc/opts-global.c
> > index b1a8429dc3c..574db430430 100644
> > --- a/gcc/opts-global.c
> > +++ b/gcc/opts-global.c
> > @@ -380,6 +380,10 @@ handle_common_deferred_options (void)
> >          add_debug_prefix_map (opt->arg);
> >          break;
> >
> > +       case OPT_fmacro_prefix_map_:
> > +         add_macro_prefix_map (opt->arg);
> > +         break;
> > +
> >        case OPT_ffile_prefix_map_:
> >          add_file_prefix_map (opt->arg);
> >          break;
> > diff --git a/gcc/testsuite/gfortran.dg/pr96069.f90
> > b/gcc/testsuite/gfortran.dg/pr96069.f90
> > new file mode 100644
> > index 00000000000..d7fed59a150
> > --- /dev/null
> > +++ b/gcc/testsuite/gfortran.dg/pr96069.f90
> > @@ -0,0 +1,11 @@
> > +! { dg-do compile }
> > +! { dg-options "-fmacro-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" } }
> >
> >
> >
> > >
> > > ---
> > >  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

Reply via email to