public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Map filename from print in gfortran with -ffile-prefix-map (PR96069)
@ 2020-07-06  0:45 Yichao Yu
  2020-07-06  0:50 ` [PATCH] " Yichao Yu
  0 siblings, 1 reply; 7+ messages in thread
From: Yichao Yu @ 2020-07-06  0:45 UTC (permalink / raw)
  To: GCC Patches

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] Map filename from print in gfortran with -ffile-prefix-map (PR96069)
  2020-07-06  0:45 Map filename from print in gfortran with -ffile-prefix-map (PR96069) Yichao Yu
@ 2020-07-06  0:50 ` Yichao Yu
  2020-07-06  1:29   ` Yichao Yu
  0 siblings, 1 reply; 7+ messages in thread
From: Yichao Yu @ 2020-07-06  0:50 UTC (permalink / raw)
  To: GCC Patches

Sorry I think I accidentally had rich text mode on and also forgot the
`[PATCH]` in the title in the previous email... Try again...

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 to 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 --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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Map filename from print in gfortran with -ffile-prefix-map (PR96069)
  2020-07-06  0:50 ` [PATCH] " Yichao Yu
@ 2020-07-06  1:29   ` Yichao Yu
  2020-07-08 13:52     ` Yichao Yu
  0 siblings, 1 reply; 7+ messages in thread
From: Yichao Yu @ 2020-07-06  1:29 UTC (permalink / raw)
  To: GCC Patches

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

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Map filename from print in gfortran with -ffile-prefix-map (PR96069)
  2020-07-06  1:29   ` Yichao Yu
@ 2020-07-08 13:52     ` Yichao Yu
  2020-07-28 15:12       ` Yichao Yu
  2020-07-28 20:52       ` Thomas Koenig
  0 siblings, 2 replies; 7+ messages in thread
From: Yichao Yu @ 2020-07-08 13:52 UTC (permalink / raw)
  To: GCC Patches, fortran

Forwarding to fortran@gcc.gnu.org as suggested by Dominique d'Humieres.

On Sun, Jul 5, 2020 at 9:29 PM Yichao Yu <yyc1992@gmail.com> wrote:
>
> > 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...)
>
> 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Map filename from print in gfortran with -ffile-prefix-map (PR96069)
  2020-07-08 13:52     ` Yichao Yu
@ 2020-07-28 15:12       ` Yichao Yu
  2020-07-28 20:52       ` Thomas Koenig
  1 sibling, 0 replies; 7+ messages in thread
From: Yichao Yu @ 2020-07-28 15:12 UTC (permalink / raw)
  To: GCC Patches, fortran

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Map filename from print in gfortran with -ffile-prefix-map (PR96069)
  2020-07-08 13:52     ` Yichao Yu
  2020-07-28 15:12       ` Yichao Yu
@ 2020-07-28 20:52       ` Thomas Koenig
  2020-07-28 21:02         ` Yichao Yu
  1 sibling, 1 reply; 7+ messages in thread
From: Thomas Koenig @ 2020-07-28 20:52 UTC (permalink / raw)
  To: Yichao Yu, GCC Patches, fortran

Hi Yichao,

> Forwarding to fortran@gcc.gnu.org as suggested by Dominique d'Humieres.
> 
> On Sun, Jul 5, 2020 at 9:29 PM Yichao Yu <yyc1992@gmail.com> wrote:
>>
>>> 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.

Best regards

	Thomas

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Map filename from print in gfortran with -ffile-prefix-map (PR96069)
  2020-07-28 20:52       ` Thomas Koenig
@ 2020-07-28 21:02         ` Yichao Yu
  0 siblings, 0 replies; 7+ messages in thread
From: Yichao Yu @ 2020-07-28 21:02 UTC (permalink / raw)
  To: Thomas Koenig; +Cc: GCC Patches, fortran

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-07-28 21:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-06  0:45 Map filename from print in gfortran with -ffile-prefix-map (PR96069) Yichao Yu
2020-07-06  0:50 ` [PATCH] " Yichao Yu
2020-07-06  1:29   ` Yichao Yu
2020-07-08 13:52     ` Yichao Yu
2020-07-28 15:12       ` Yichao Yu
2020-07-28 20:52       ` Thomas Koenig
2020-07-28 21:02         ` Yichao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).