https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70268

--- Comment #16 from boris at gcc dot gnu.org ---
Author: boris
Date: Thu Jan 18 13:17:37 2018
New Revision: 256847

URL: https://gcc.gnu.org/viewcvs?rev=256847&root=gcc&view=rev
Log:
Add ability to remap file names in __FILE__, etc (PR other/70268)

This commit adds the -fmacro-prefix-map option that allows remapping of file
names in __FILE__, __BASE_FILE__, and __builtin_FILE(), similar to how
-fdebug-prefix-map allows to do the same for debug information.

Additionally, it adds -ffile-prefix-map which can be used to specify both
mappings with a single option (and, should we need to add more -f*-prefix-map
options in the future, those as well).

libcpp/ChangeLog:

2018-01-18  Boris Kolpackov  <bo...@codesynthesis.com>

        PR other/70268
        * include/cpplib.h (cpp_callbacks::remap_filename): New callback.
        * libcpp/macro.c (_cpp_builtin_macro_text): Call remap_filename for
        __FILE__ and __BASE_FILE__.


gcc/ChangeLog:

2018-01-18  Boris Kolpackov  <bo...@codesynthesis.com>

        PR other/70268
        * common.opt: (-ffile-prefix-map): New option.
        * opts.c (common_handle_option): Defer it.
        * opts-global.c (handle_common_deferred_options): Handle it.
        * debug.h (remap_debug_filename, add_debug_prefix_map): Move to...
        * file-prefix-map.h: New file.
        (remap_debug_filename, add_debug_prefix_map): ...here.
        (add_macro_prefix_map, add_file_prefix_map, remap_macro_filename): New.
        * final.c (debug_prefix_map, add_debug_prefix_map
        remap_debug_filename): Move to...
        * file-prefix-map.c: New file.
        (file_prefix_map, add_prefix_map, remap_filename) ...here and rename,
        generalize, get rid of alloca(), use strrchr() instead of strchr().
        (add_macro_prefix_map, add_debug_prefix_map, add_file_prefix_map):
        Implement in terms of add_prefix_map().
        (remap_macro_filename, remap_debug_filename): Implement in term of
        remap_filename().
        * Makefile.in (OBJS, PLUGIN_HEADERS): Add new files.
        * builtins.c (fold_builtin_FILE): Call remap_macro_filename().
        * dbxout.c: Include file-prefix-map.h.
        * varasm.c: Likewise.
        * vmsdbgout.c: Likewise.
        * xcoffout.c: Likewise.
        * dwarf2out.c: Likewise plus omit new options from DW_AT_producer.
        * doc/cppopts.texi (-fmacro-prefix-map): Document.
        * doc/invoke.texi (-ffile-prefix-map): Document.
        (-fdebug-prefix-map): Update description.


gcc/c-family/ChangeLog:

2018-01-18  Boris Kolpackov  <bo...@codesynthesis.com>

        PR other/70268
        * c-family/c.opt (-fmacro-prefix-map): New option.
        * c-family/c-opts.c (c_common_handle_option): Handle it.
        * c-family/c-lex.c (init_c_lex): Set remap_filename cpp callback.
        * c-family/c-ppoutput.c (init_pp_output): Likewise.


gcc/testsuite/ChangeLog:

2018-01-18  Boris Kolpackov  <bo...@codesynthesis.com>

        PR other/70268
        * c-c++-common/ffile-prefix-map.c: New test.
        * c-c++-common/fmacro-prefix-map.c: New test.
        * c-c++-common/cpp/ffile-prefix-map.c: New test.
        * c-c++-common/cpp/fmacro-prefix-map.c: New test.


Added:
    trunk/gcc/file-prefix-map.c
    trunk/gcc/file-prefix-map.h   (with props)
    trunk/gcc/testsuite/c-c++-common/cpp/ffile-prefix-map.c
    trunk/gcc/testsuite/c-c++-common/cpp/fmacro-prefix-map.c
    trunk/gcc/testsuite/c-c++-common/ffile-prefix-map.c
    trunk/gcc/testsuite/c-c++-common/fmacro-prefix-map.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/Makefile.in
    trunk/gcc/builtins.c
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-lex.c
    trunk/gcc/c-family/c-opts.c
    trunk/gcc/c-family/c-ppoutput.c
    trunk/gcc/c-family/c.opt
    trunk/gcc/common.opt
    trunk/gcc/dbxout.c
    trunk/gcc/debug.h
    trunk/gcc/doc/cppopts.texi
    trunk/gcc/doc/invoke.texi
    trunk/gcc/dwarf2out.c
    trunk/gcc/final.c
    trunk/gcc/opts-global.c
    trunk/gcc/opts.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/varasm.c
    trunk/gcc/vmsdbgout.c
    trunk/gcc/xcoffout.c
    trunk/libcpp/ChangeLog
    trunk/libcpp/include/cpplib.h
    trunk/libcpp/macro.c

Propchange: trunk/gcc/file-prefix-map.h
            ('svn:eol-style' added)

Propchange: trunk/gcc/file-prefix-map.h
            ('svn:keywords' added)

Reply via email to