diff options
author | Boris Kolpackov <boris@gcc.gnu.org> | 2018-01-18 13:17:37 +0000 |
---|---|---|
committer | Boris Kolpackov <boris@gcc.gnu.org> | 2018-01-18 13:17:37 +0000 |
commit | 7365279fca30371b07e49bfa83a23ddc44cc3860 (patch) | |
tree | 0cf4591ae68fe77087037b6e15317e5792deed8f /gcc/c-family | |
parent | 82a7bb2dff8f2055e64f14cff0e3e29d0c83c195 (diff) | |
download | gcc-7365279fca30371b07e49bfa83a23ddc44cc3860.zip gcc-7365279fca30371b07e49bfa83a23ddc44cc3860.tar.gz gcc-7365279fca30371b07e49bfa83a23ddc44cc3860.tar.bz2 |
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 <boris@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 <boris@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 <boris@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 <boris@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.
From-SVN: r256847
Diffstat (limited to 'gcc/c-family')
-rw-r--r-- | gcc/c-family/ChangeLog | 16 | ||||
-rw-r--r-- | gcc/c-family/c-lex.c | 2 | ||||
-rw-r--r-- | gcc/c-family/c-opts.c | 5 | ||||
-rw-r--r-- | gcc/c-family/c-ppoutput.c | 2 | ||||
-rw-r--r-- | gcc/c-family/c.opt | 4 |
5 files changed, 25 insertions, 4 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index d5012e2..7d29382 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,11 @@ +2018-01-18 Boris Kolpackov <boris@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. + 2018-01-17 David Malcolm <dmalcolm@redhat.com> PR c++/83814 @@ -119,7 +127,7 @@ 2017-12-14 Qing Zhao <qing.zhao@oracle.com> - PR middle_end/79538 + PR middle_end/79538 * c-cppbuiltin.c (builtin_define_with_hex_fp_value): Adjust the size of buf1 and buf2, add a new buf to avoid format-overflow warning. @@ -463,7 +471,7 @@ (set_std_cxx17): ... this. (c_common_handle_option): Rename OPT_std_c__1z to OPT_std_c__17 and OPT_std_gnu__1z to OPT_std_gnu__17. Adjust set_std_cxx1z - caller. + caller. (c_common_post_options): Use cxx17 instead of cxx1z. Adjust comments. @@ -2430,7 +2438,7 @@ Matthias Klose <doko@debian.org> * c-common.c (get_source_date_epoch): New function, gets the environment - variable SOURCE_DATE_EPOCH and parses it as long long with error + variable SOURCE_DATE_EPOCH and parses it as long long with error handling. * c-common.h (get_source_date_epoch): Prototype. * c-lex.c (c_lex_with_flags): set parse_in->source_date_epoch. @@ -2901,7 +2909,7 @@ 2015-11-12 James Norris <jnorris@codesourcery.com> Joseph Myers <joseph@codesourcery.com> - * c-pragma.c (oacc_pragmas): Add entry for declare directive. + * c-pragma.c (oacc_pragmas): Add entry for declare directive. * c-pragma.h (enum pragma_kind): Add PRAGMA_OACC_DECLARE. (enum pragma_omp_clause): Add PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT and PRAGMA_OACC_CLAUSE_LINK. diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c index e82670f..a4ad0a3 100644 --- a/gcc/c-family/c-lex.c +++ b/gcc/c-family/c-lex.c @@ -27,6 +27,7 @@ along with GCC; see the file COPYING3. If not see #include "stor-layout.h" #include "c-pragma.h" #include "debug.h" +#include "file-prefix-map.h" /* remap_macro_filename() */ #include "attribs.h" @@ -82,6 +83,7 @@ init_c_lex (void) cb->has_attribute = c_common_has_attribute; cb->get_source_date_epoch = cb_get_source_date_epoch; cb->get_suggestion = cb_get_suggestion; + cb->remap_filename = remap_macro_filename; /* Set the debug callbacks if we can use them. */ if ((debug_info_level == DINFO_LEVEL_VERBOSE diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c index f84ecf4..3db01d4 100644 --- a/gcc/c-family/c-opts.c +++ b/gcc/c-family/c-opts.c @@ -40,6 +40,7 @@ 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 @@ -448,6 +449,10 @@ c_common_handle_option (size_t scode, const char *arg, 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-ppoutput.c b/gcc/c-family/c-ppoutput.c index 9d08776..8c525caf 100644 --- a/gcc/c-family/c-ppoutput.c +++ b/gcc/c-family/c-ppoutput.c @@ -22,6 +22,7 @@ #include "c-common.h" /* For flags. */ #include "../libcpp/internal.h" #include "c-pragma.h" /* For parse_in. */ +#include "file-prefix-map.h" /* remap_macro_filename() */ /* Encapsulates state used to convert a stream of tokens into a text file. */ @@ -151,6 +152,7 @@ init_pp_output (FILE *out_stream) cb->has_attribute = c_common_has_attribute; cb->get_source_date_epoch = cb_get_source_date_epoch; + cb->remap_filename = remap_macro_filename; /* Initialize the print structure. */ print.src_line = 1; diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 16a515a..9c71726 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -1390,6 +1390,10 @@ 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__, and __builtin_FILE(). + fdump-ada-spec C ObjC C++ ObjC++ RejectNegative Var(flag_dump_ada_spec) Write all declarations as Ada code transitively. |