diff options
author | Nathan Sidwell <nathan@acm.org> | 2021-02-19 09:18:13 -0800 |
---|---|---|
committer | Nathan Sidwell <nathan@acm.org> | 2021-02-19 09:40:12 -0800 |
commit | bfe83ae38e871a2e4205ce63fd9d3247dff412bd (patch) | |
tree | 8e723cf7a4017d46a7aa27d45cbb77972e7188e8 /gcc/cp/module.cc | |
parent | f86e187e12db14ad1cced26b9f8aafb06498e208 (diff) | |
download | gcc-bfe83ae38e871a2e4205ce63fd9d3247dff412bd.zip gcc-bfe83ae38e871a2e4205ce63fd9d3247dff412bd.tar.gz gcc-bfe83ae38e871a2e4205ce63fd9d3247dff412bd.tar.bz2 |
c++: Inform of CMI reads [PR 99166]
When successfully reading a module CMI, the user gets no indication of
where that CMI was located. I originally didn't consider this a
problem -- the read was successful after all. But it can make it
difficult to interact with build systems, particularly when caching
can be involved. Grovelling over internal dump files is not really
useful to the user. Hence this option, which is similar to the
-flang-info-include-translate variants, and allows the user to ask for
all, or specific module read notification.
gcc/c-family/
* c.opt (flang-info-module-read, flang-info-module-read=): New.
gcc/
* doc/invoke.texi (flang-info-module-read): Document.
gcc/cp/
* module.cc (note_cmis): New.
(struct module_state): Add inform_read_p bit.
(module_state::do_import): Inform of CMI location, if enabled.
(init_modules): Canonicalize note_cmis entries.
(handle_module_option): Handle -flang-info-module-read=FOO.
gcc/testsuite/
* g++.dg/modules/pr99166_a.X: New.
* g++.dg/modules/pr99166_b.C: New.
* g++.dg/modules/pr99166_c.C: New.
* g++.dg/modules/pr99166_d.C: New.
Diffstat (limited to 'gcc/cp/module.cc')
-rw-r--r-- | gcc/cp/module.cc | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index e801c52..691381b 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -317,6 +317,9 @@ version2string (unsigned version, verstr_t &out) /* Include files to note translation for. */ static vec<const char *, va_heap, vl_embed> *note_includes; +/* Modules to note CMI pathames. */ +static vec<const char *, va_heap, vl_embed> *note_cmis; + /* Traits to hash an arbitrary pointer. Entries are not deletable, and removal is a noop (removal needed upon destruction). */ template <typename T> @@ -3547,9 +3550,10 @@ class GTY((chain_next ("%h.parent"), for_user)) module_state { do it again */ bool call_init_p : 1; /* This module's global initializer needs calling. */ + bool inform_read_p : 1; /* Inform of a read. */ /* Record extensions emitted or permitted. */ unsigned extensions : SE_BITS; - /* 12 bits used, 4 bits remain */ + /* 13 bits used, 3 bits remain */ public: module_state (tree name, module_state *, bool); @@ -3782,6 +3786,8 @@ module_state::module_state (tree name, module_state *parent, bool partition) partition_p = partition; + inform_read_p = false; + extensions = 0; if (name && TREE_CODE (name) == STRING_CST) { @@ -18634,6 +18640,8 @@ module_state::do_import (cpp_reader *reader, bool outermost) { const char *file = maybe_add_cmi_prefix (filename); dump () && dump ("CMI is %s", file); + if (note_module_read_yes || inform_read_p) + inform (loc, "reading CMI %qs", file); fd = open (file, O_RDONLY | O_CLOEXEC | O_BINARY); e = errno; } @@ -19545,6 +19553,7 @@ init_modules (cpp_reader *reader) headers = BITMAP_GGC_ALLOC (); if (note_includes) + /* Canonicalize header names. */ for (unsigned ix = 0; ix != note_includes->length (); ix++) { const char *hdr = (*note_includes)[ix]; @@ -19567,6 +19576,37 @@ init_modules (cpp_reader *reader) (*note_includes)[ix] = path; } + if (note_cmis) + /* Canonicalize & mark module names. */ + for (unsigned ix = 0; ix != note_cmis->length (); ix++) + { + const char *name = (*note_cmis)[ix]; + size_t len = strlen (name); + + bool is_system = name[0] == '<'; + bool is_user = name[0] == '"'; + bool is_pathname = false; + if (!(is_system || is_user)) + for (unsigned ix = len; !is_pathname && ix--;) + is_pathname = IS_DIR_SEPARATOR (name[ix]); + if (is_system || is_user || is_pathname) + { + if (len <= (is_pathname ? 0 : 2) + || (!is_pathname && name[len-1] != (is_system ? '>' : '"'))) + { + error ("invalid header name %qs", name); + continue; + } + else + name = canonicalize_header_name (is_pathname ? nullptr : reader, + 0, is_pathname, name, len); + } + if (auto module = get_module (name)) + module->inform_read_p = 1; + else + error ("invalid module name %qs", name); + } + dump.push (NULL); /* Determine lazy handle bound. */ @@ -19952,6 +19992,10 @@ handle_module_option (unsigned code, const char *str, int) vec_safe_push (note_includes, str); return true; + case OPT_flang_info_module_read_: + vec_safe_push (note_cmis, str); + return true; + default: return false; } |