[13/32] new options

Message ID 6e4bc3b9-4263-b114-b118-fcb5799976fb@acm.org
State New
Headers show
Series
  • C++ 20 Modules
Related show

Commit Message

Nathan Sidwell Nov. 3, 2020, 9:15 p.m.
Here are the new options, along with the C++ lang-spec changes.

Modules is enabled by -fmodules-ts, it is not implicitly enabled by 
-std=c++20.  Usually that's the only option you need to add for a 
module-aware build.

to build a header unit you can either add -fmodule-header to a c++ 
build, or you can set the language to be c++-header and add -fmodules-ts:

g++ -x c++-header -fmodules-ts my-header-file

to search the user or system include paths select c++-user-header of 
c++-system-header as the language.

enabling -fmodules-ts will disable PCH, they do not play well together. 
There is a potential issue down the road when we implicitly enable 
modules.  At that point building a header-unit could become 
indistinguishable from building a PCH.  Perhaps we should consider 
phasing in an explicit PCH option?

-- 
Nathan Sidwell

Comments

Jakub Jelinek via Gcc-patches Nov. 25, 2020, 7:27 p.m. | #1
On 11/3/20 2:15 PM, Nathan Sidwell wrote:
> Here are the new options, along with the C++ lang-spec changes.

>

> Modules is enabled by -fmodules-ts, it is not implicitly enabled by

> -std=c++20.  Usually that's the only option you need to add for a

> module-aware build.

>

> to build a header unit you can either add -fmodule-header to a c++

> build, or you can set the language to be c++-header and add -fmodules-ts:

>

> g++ -x c++-header -fmodules-ts my-header-file

>

> to search the user or system include paths select c++-user-header of

> c++-system-header as the language.

>

> enabling -fmodules-ts will disable PCH, they do not play well

> together. There is a potential issue down the road when we implicitly

> enable modules.  At that point building a header-unit could become

> indistinguishable from building a PCH.  Perhaps we should consider

> phasing in an explicit PCH option?

In a modules capable world, how much value still exists with the old PCH
scheme?   The old PCH scheme can't work in some enviroments anyway
(anyone using ASLR & PIE).

I'm going to assume the spec changs are OK.  My brain always melts when
I start looking at them.

OK

Jeff

Patch

diff --git c/gcc/c-family/c-opts.c w/gcc/c-family/c-opts.c
index 120f4489f6c..c8f08d9e014 100644
--- c/gcc/c-family/c-opts.c
+++ w/gcc/c-family/c-opts.c
@@ -234,6 +234,7 @@  c_common_init_options (unsigned int decoded_options_count,
   cpp_opts = cpp_get_options (parse_in);
   cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
   cpp_opts->objc = c_dialect_objc ();
+  cpp_opts->deps.modules = true;
 
   /* Reset to avoid warnings on internal definitions.  We set it just
      before passing on command-line options to cpplib.  */
@@ -367,6 +368,18 @@  c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
       cpp_opts->deps.phony_targets = true;
       break;
 
+    case OPT_Mmodules:
+      /* Do not set deps_seen, so the user can unconditionally turn
+	 this on or off.  */
+      cpp_opts->deps.modules = true;
+      break;
+
+    case OPT_Mno_modules:
+      /* Do not set deps_seen, so the user can unconditionally turn
+	 this on or off.  */
+      cpp_opts->deps.modules = false;
+      break;
+
     case OPT_MQ:
     case OPT_MT:
       deps_seen = true;
diff --git c/gcc/c-family/c-pch.c w/gcc/c-family/c-pch.c
index a2292f46a7d..f55a1fde3ad 100644
--- c/gcc/c-family/c-pch.c
+++ w/gcc/c-family/c-pch.c
@@ -206,6 +206,10 @@  c_common_valid_pch (cpp_reader *pfile, const char *name, int fd)
   /* Perform a quick test of whether this is a valid
      precompiled header for the current language.  */
 
+  /* C++ modules and PCH don't play together.  */
+  if (flag_modules)
+    return 2;
+
   sizeread = read (fd, ident, IDENT_LENGTH + 16);
   if (sizeread == -1)
     fatal_error (input_location, "cannot read %s: %m", name);
diff --git c/gcc/c-family/c.opt w/gcc/c-family/c.opt
index 10e53ea67c9..1edc7f2b2bd 100644
--- c/gcc/c-family/c.opt
+++ w/gcc/c-family/c.opt
@@ -236,6 +236,14 @@  MMD
 C ObjC C++ ObjC++ NoDriverArg Separate MissingArgError(missing filename after %qs)
 Like -MD but ignore system header files.
 
+Mmodules
+C++
+Generate C++ Module dependency information.
+
+Mno-modules
+C++
+; undocumented
+
 MP
 C ObjC C++ ObjC++
 Generate phony targets for all headers.
@@ -1666,6 +1674,53 @@  flax-vector-conversions
 C ObjC C++ ObjC++ Var(flag_lax_vector_conversions)
 Allow implicit conversions between vectors with differing numbers of subparts and/or differing element types.
 
+fmodules-ts
+C++ ObjC++ Var(flag_modules) Integer Init(0)
+Enable C++ modules-ts (experimental).
+
+fno-modules
+C++ ObjC++ Undocumented RejectNegative Var(flag_modules,0) Integer
+;; undocumented
+
+fmodule-header
+C++ ObjC RejectNegative Var(flag_header_unit,0) Integer
+Enable C++ header module (experimental).
+
+fmodule-header=
+C++ ObjC++ Joined RejectNegative Undocumented
+
+fmodule-implicit-inline
+C++ ObjC++ Var(flag_module_implicit_inline,0) Integer
+Member functions defined within their class are inline in module purview.
+
+fmodule-only
+C++ ObjC RejectNegative Var(flag_module_only) Integer
+Only emit Binary Module Interface.
+
+fmodule-mapper=
+C++ ObjC++ Joined RejectNegative MissingArgError(missing mapper)
+Mapper for module to CMI files.
+
+fmodule-lazy
+C++ ObjC++ Var(flag_module_lazy) Init(1)
+Enable lazy module importing.
+
+fmodule-version-ignore
+C++ ObjC Var(flag_module_version_ignore) Integer
+; undocumented, Very dangerous, but occasionally useful
+
+Winvalid-imported-macros
+C++ ObjC++ Var(warn_imported_macros)
+Warn about macros that have conflicting header units definitions.
+
+flang-info-include-translate
+C++ Var(note_include_translate)
+Note #include directives translated to import declarations.
+
+flang-info-include-translate=
+C++ Joined RejectNegative MissingArgError(missing header name)
+Note a #include translation of a specific header.
+
 fmax-include-depth=
 C ObjC C++ ObjC++ Joined RejectNegative UInteger
 fmax-include-depth=<number> Set the maximum depth of the nested #include.
diff --git c/gcc/cp/lang-specs.h w/gcc/cp/lang-specs.h
index 0ad4a33b93e..1388aaed198 100644
--- c/gcc/cp/lang-specs.h
+++ w/gcc/cp/lang-specs.h
@@ -40,17 +40,57 @@  along with GCC; see the file COPYING3.  If not see
   {".tcc", "@c++-header", 0, 0, 0},
   {".hh",  "@c++-header", 0, 0, 0},
   {"@c++-header",
-      "%{E|M|MM:cc1plus -E %(cpp_options) %2 %(cpp_debug_options)}"
+      "%{E|M|MM:cc1plus -E %{fmodules-ts:-fdirectives-only -fmodule-header}"
+      "  %(cpp_options) %2 %(cpp_debug_options)}"
+      "%{!E:%{!M:%{!MM:"
+      "  %{save-temps*|no-integrated-cpp:cc1plus -E"
+      "    %{fmodules-ts:-fdirectives-only -fmodule-header}"
+      "	   %(cpp_options) %2 -o %{save-temps*:%b.ii} %{!save-temps*:%g.ii} \n}"
+      "  cc1plus %{save-temps*|no-integrated-cpp:-fpreprocessed"
+      "            %{fmodules-ts:-fdirectives-only}"
+      " 	   %{save-temps*:%b.ii} %{!save-temps*:%g.ii}}"
+      "  %{!save-temps*:%{!no-integrated-cpp:%(cpp_unique_options)}}"
+      "  %{fmodules-ts:-fmodule-header %{fpreprocessed:-fdirectives-only}}"
+      "  %(cc1_options) %2"
+      "  %{!S:-o %g.s%V}"
+      "  %{!fsyntax-only:%{!fmodule-*:%{!fmodules-*:%{!fdump-ada-spec*:"
+      "	     %{!o*:--output-pch=%i.gch}%W{o*:--output-pch=%*}}}}}}}}",
+     CPLUSPLUS_CPP_SPEC, 0, 0},
+  {"@c++-system-header",
+      "%{E|M|MM:cc1plus -E"
+      "  %{fmodules-ts:-fdirectives-only -fmodule-header=system}"
+      "  %(cpp_options) %2 %(cpp_debug_options)}"
       "%{!E:%{!M:%{!MM:"
       "  %{save-temps*|no-integrated-cpp:cc1plus -E"
+      "    %{fmodules-ts:-fdirectives-only -fmodule-header=system}"
       "	   %(cpp_options) %2 -o %{save-temps*:%b.ii} %{!save-temps*:%g.ii} \n}"
       "  cc1plus %{save-temps*|no-integrated-cpp:-fpreprocessed"
+      "            %{fmodules-ts:-fdirectives-only}"
       " 	   %{save-temps*:%b.ii} %{!save-temps*:%g.ii}}"
       "  %{!save-temps*:%{!no-integrated-cpp:%(cpp_unique_options)}}"
+      "  %{fmodules-ts:-fmodule-header=system %{fpreprocessed:-fdirectives-only}}"
       "  %(cc1_options) %2"
-      "  %{!fsyntax-only:%{!S:-o %g.s}"
-      "    %{!fdump-ada-spec*:%{!o*:--output-pch=%i.gch}"
-      "      %W{o*:--output-pch=%*}}%V}}}}",
+      "  %{!S:-o %g.s%V}"
+      "  %{!fsyntax-only:%{!fmodule-*:%{!fmodules-*:%{!fdump-ada-spec*:"
+      "	     %{!o*:--output-pch=%i.gch}%W{o*:--output-pch=%*}}}}}}}}",
+     CPLUSPLUS_CPP_SPEC, 0, 0},
+  {"@c++-user-header",
+      "%{E|M|MM:cc1plus -E"
+      "  %{fmodules-ts:-fdirectives-only -fmodule-header=user}"
+      "  %(cpp_options) %2 %(cpp_debug_options)}"
+      "%{!E:%{!M:%{!MM:"
+      "  %{save-temps*|no-integrated-cpp:cc1plus -E"
+      "    %{fmodules-ts:-fdirectives-only -fmodule-header=user}"
+      "	   %(cpp_options) %2 -o %{save-temps*:%b.ii} %{!save-temps*:%g.ii} \n}"
+      "  cc1plus %{save-temps*|no-integrated-cpp:-fpreprocessed"
+      "            %{fmodules-ts:-fdirectives-only}"
+      " 	   %{save-temps*:%b.ii} %{!save-temps*:%g.ii}}"
+      "  %{!save-temps*:%{!no-integrated-cpp:%(cpp_unique_options)}}"
+      "  %{fmodules-ts:-fmodule-header=user %{fpreprocessed:-fdirectives-only}}"
+      "  %(cc1_options) %2"
+      "  %{!S:-o %g.s%V}"
+      "  %{!fsyntax-only:%{!fmodule-*:%{!fmodules-*:%{!fdump-ada-spec*:"
+      "	     %{!o*:--output-pch=%i.gch}%W{o*:--output-pch=%*}}}}}}}}",
      CPLUSPLUS_CPP_SPEC, 0, 0},
   {"@c++",
       "%{E|M|MM:cc1plus -E %(cpp_options) %2 %(cpp_debug_options)}"
@@ -60,11 +100,14 @@  along with GCC; see the file COPYING3.  If not see
       "  cc1plus %{save-temps*|no-integrated-cpp:-fpreprocessed"
       " 	   %{save-temps*:%b.ii} %{!save-temps*:%g.ii}}"
       "  %{!save-temps*:%{!no-integrated-cpp:%(cpp_unique_options)}}"
-      "	 %(cc1_options) %2"
-      "  %{!fsyntax-only:%(invoke_as)}}}}",
+      "  %(cc1_options) %2"
+      "  %{fmodule-only:%{!S:-o %g.s%V}}"
+      "  %{!fsyntax-only:%{!fmodule-only:%(invoke_as)}}}}}",
       CPLUSPLUS_CPP_SPEC, 0, 0},
   {".ii", "@c++-cpp-output", 0, 0, 0},
   {"@c++-cpp-output",
       "%{!E:%{!M:%{!MM:"
       "  cc1plus -fpreprocessed %i %(cc1_options) %2"
-      "  %{!fsyntax-only:%(invoke_as)}}}}", 0, 0, 0},
+      "  %{fmodule-only:%{!S:-o %g.s%V}}"
+      "  %{!fsyntax-only:%{!fmodule-only:%{!fmodule-header*:"
+      "     %(invoke_as)}}}}}}", 0, 0, 0},