aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@gcc.gnu.org>2018-01-18 13:17:37 +0000
committerBoris Kolpackov <boris@gcc.gnu.org>2018-01-18 13:17:37 +0000
commit7365279fca30371b07e49bfa83a23ddc44cc3860 (patch)
tree0cf4591ae68fe77087037b6e15317e5792deed8f /libcpp
parent82a7bb2dff8f2055e64f14cff0e3e29d0c83c195 (diff)
downloadgcc-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 'libcpp')
-rw-r--r--libcpp/ChangeLog15
-rw-r--r--libcpp/include/cpplib.h4
-rw-r--r--libcpp/macro.c2
3 files changed, 17 insertions, 4 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index b69e364..5d2aa26 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,10 @@
+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__.
+
2018-01-10 Kelvin Nilsen <kelvin@gcc.gnu.org>
* lex.c (search_line_fast): Remove illegal coercion of an
@@ -19,7 +26,7 @@
2017-12-14 Bernd Edlinger <bernd.edlinger@hotmail.de>
* internal.h (maybe_print_line): Change signature.
-
+
2017-12-05 Jakub Jelinek <jakub@redhat.com>
PR c++/79228
@@ -714,9 +721,9 @@
* init.c (cpp_init_source_date_epoch): New function.
* internal.h: Added source_date_epoch variable to struct
cpp_reader to store a reproducible date.
- * macro.c (_cpp_builtin_macro_text): Set pfile->date timestamp from
- pfile->source_date_epoch instead of localtime if source_date_epoch is
- set, to be used for __DATE__ and __TIME__ macros to help reproducible
+ * macro.c (_cpp_builtin_macro_text): Set pfile->date timestamp from
+ pfile->source_date_epoch instead of localtime if source_date_epoch is
+ set, to be used for __DATE__ and __TIME__ macros to help reproducible
builds.
2016-04-13 Bernd Schmidt <bschmidt@redhat.com>
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index 7cc40c6..9814d0d 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -622,6 +622,10 @@ struct cpp_callbacks
C++-style comments it does not include the terminating newline. */
void (*comment) (cpp_reader *, source_location, const unsigned char *,
size_t);
+
+ /* Callback for filename remapping in __FILE__ and __BASE_FILE__ macro
+ expansions. */
+ const char *(*remap_filename) (const char*);
};
#ifdef VMS
diff --git a/libcpp/macro.c b/libcpp/macro.c
index 0f9f063..c5f3ffd 100644
--- a/libcpp/macro.c
+++ b/libcpp/macro.c
@@ -450,6 +450,8 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node,
if (!name)
abort ();
}
+ if (pfile->cb.remap_filename)
+ name = pfile->cb.remap_filename (name);
len = strlen (name);
buf = _cpp_unaligned_alloc (pfile, len * 2 + 3);
result = buf;