aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/module.cc
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2023-09-01 09:04:02 -0400
committerJason Merrill <jason@redhat.com>2023-09-19 17:32:23 -0400
commit024f135a1e9b8f8e102960357cae6e99e1dbe6eb (patch)
treee03784e8f1a657a82139f213aa03f199f7d0cec9 /gcc/cp/module.cc
parent1e44764bb381bf9594fcefdc95678a872adc1927 (diff)
downloadgcc-024f135a1e9b8f8e102960357cae6e99e1dbe6eb.zip
gcc-024f135a1e9b8f8e102960357cae6e99e1dbe6eb.tar.gz
gcc-024f135a1e9b8f8e102960357cae6e99e1dbe6eb.tar.bz2
p1689r5: initial support
This patch implements support for [P1689R5][] to communicate to a build system the C++20 module dependencies to build systems so that they may build `.gcm` files in the proper order. Support is communicated through the following three new flags: - `-fdeps-format=` specifies the format for the output. Currently named `p1689r5`. - `-fdeps-file=` specifies the path to the file to write the format to. - `-fdeps-target=` specifies the `.o` that will be written for the TU that is scanned. This is required so that the build system can correlate the dependency output with the actual compilation that will occur. CMake supports this format as of 17 Jun 2022 (to be part of 3.25.0) using an experimental feature selection (to allow for future usage evolution without committing to how it works today). While it remains experimental, docs may be found in CMake's documentation for experimental features. Future work may include using this format for Fortran module dependencies as well, however this is still pending work. [P1689R5]: https://isocpp.org/files/papers/P1689R5.html [cmake-experimental]: https://gitlab.kitware.com/cmake/cmake/-/blob/master/Help/dev/experimental.rst TODO: - header-unit information fields Header units (including the standard library headers) are 100% unsupported right now because the `-E` mechanism wants to import their BMIs. A new mode (i.e., something more workable than existing `-E` behavior) that mocks up header units as if they were imported purely from their path and content would be required. - non-utf8 paths The current standard says that paths that are not unambiguously represented using UTF-8 are not supported (because these cases are rare and the extra complication is not worth it at this time). Future versions of the format might have ways of encoding non-UTF-8 paths. For now, this patch just doesn't support non-UTF-8 paths (ignoring the "unambiguously representable in UTF-8" case). - figure out why junk gets placed at the end of the file Sometimes it seems like the file gets a lot of `NUL` bytes appended to it. It happens rarely and seems to be the result of some `ftruncate`-style call which results in extra padding in the contents. Noting it here as an observation at least. libcpp/ * include/cpplib.h: Add cpp_fdeps_format enum. (cpp_options): Add fdeps_format field (cpp_finish): Add structured dependency fdeps_stream parameter. * include/mkdeps.h (deps_add_module_target): Add flag for whether a module is exported or not. (fdeps_add_target): Add function. (deps_write_p1689r5): Add function. * init.cc (cpp_finish): Add new preprocessor parameter used for C++ module tracking. * mkdeps.cc (mkdeps): Implement P1689R5 output. gcc/ * doc/invoke.texi: Document -fdeps-format=, -fdeps-file=, and -fdeps-target= flags. * gcc.cc: add defaults for -fdeps-target= and -fdeps-file= when only -fdeps-format= is specified. * json.h: Add a TODO item to refactor out to share with `libcpp/mkdeps.cc`. gcc/c-family/ * c-opts.cc (c_common_handle_option): Add fdeps_file variable and -fdeps-format=, -fdeps-file=, and -fdeps-target= parsing. * c.opt: Add -fdeps-format=, -fdeps-file=, and -fdeps-target= flags. gcc/cp/ * module.cc (preprocessed_module): Pass whether the module is exported to dependency tracking. gcc/testsuite/ * g++.dg/modules/depflags-f-MD.C: New test. * g++.dg/modules/depflags-f.C: New test. * g++.dg/modules/depflags-fi.C: New test. * g++.dg/modules/depflags-fj-MD.C: New test. * g++.dg/modules/depflags-fj.C: New test. * g++.dg/modules/depflags-fjo-MD.C: New test. * g++.dg/modules/depflags-fjo.C: New test. * g++.dg/modules/depflags-fo-MD.C: New test. * g++.dg/modules/depflags-fo.C: New test. * g++.dg/modules/depflags-j-MD.C: New test. * g++.dg/modules/depflags-j.C: New test. * g++.dg/modules/depflags-jo-MD.C: New test. * g++.dg/modules/depflags-jo.C: New test. * g++.dg/modules/depflags-o-MD.C: New test. * g++.dg/modules/depflags-o.C: New test. * g++.dg/modules/p1689-1.C: New test. * g++.dg/modules/p1689-1.exp.ddi: New test expectation. * g++.dg/modules/p1689-2.C: New test. * g++.dg/modules/p1689-2.exp.ddi: New test expectation. * g++.dg/modules/p1689-3.C: New test. * g++.dg/modules/p1689-3.exp.ddi: New test expectation. * g++.dg/modules/p1689-4.C: New test. * g++.dg/modules/p1689-4.exp.ddi: New test expectation. * g++.dg/modules/p1689-5.C: New test. * g++.dg/modules/p1689-5.exp.ddi: New test expectation. * g++.dg/modules/modules.exp: Load new P1689 library routines. * g++.dg/modules/test-p1689.py: New tool for validating P1689 output. * lib/modules.exp: Support for validating P1689 outputs. Signed-off-by: Ben Boeckel <ben.boeckel@kitware.com> Reviewed-by: Jason Merrill <jason@redhat.com>
Diffstat (limited to 'gcc/cp/module.cc')
-rw-r--r--gcc/cp/module.cc3
1 files changed, 2 insertions, 1 deletions
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index ea362bd..9df60d6 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -19834,7 +19834,8 @@ preprocessed_module (cpp_reader *reader)
&& (module->is_interface () || module->is_partition ()))
deps_add_module_target (deps, module->get_flatname (),
maybe_add_cmi_prefix (module->filename),
- module->is_header());
+ module->is_header (),
+ module->is_exported ());
else
deps_add_module_dep (deps, module->get_flatname ());
}