-- 8< --

By default, G++ puts compiled modules into a gcm.cache subdirectory of the
current working directory.  But compiled modules are specific to a
particular dialect; if the libstdc++ testsuite wants to run tests in
multiple dialects, it needs multiple gcms, and they can't all have the same
pathname.  So this patch adds the dialect to the repo path,
e.g. gcm.cache/C++20/.

The compiler modules testsuite wants to look at specific gcms directly under
gcm.cache, so I disable this behavior there.

Alternatively, this could be off by default and enable it just in the libstdc++
testsuite.  I imagine the default won't matter to most uses.  Any thoughts?

gcc/c-family/ChangeLog:

        * c.opt: Add -fmodule-repo-dialect.

gcc/cp/ChangeLog:

        * mapper-client.cc (module_client::open_module_client): Append
        default suffix to gcm.cache.
        * mapper-client.h: Adjust.
        * module.cc (make_mapper): Pass dialect name.

gcc/testsuite/ChangeLog:

        * g++.dg/modules/modules.exp: Update MOD_STD_LIST.
        Pass -fno-module-repo-dialect.
---
 gcc/c-family/c.opt                       |  4 ++++
 gcc/cp/mapper-client.h                   |  1 +
 gcc/cp/mapper-client.cc                  | 12 +++++++++++-
 gcc/cp/module.cc                         |  6 +++++-
 gcc/testsuite/g++.dg/modules/modules.exp |  9 ++++++++-
 5 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 3a895c0418c..9451c1fb4d6 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -2075,6 +2075,10 @@ fmodule-lazy
 C++ ObjC++ Var(flag_module_lazy) Init(1)
 Enable lazy module importing.
 
+fmodule-repo-dialect
+C++ ObjC++ Var(flag_module_repo_dialect) Init(1)
+Separate compiled modules in the repo by dialect.
+
 fmodule-version-ignore
 C++ ObjC Var(flag_module_version_ignore) Integer
 ; undocumented, Very dangerous, but occasionally useful
diff --git a/gcc/cp/mapper-client.h b/gcc/cp/mapper-client.h
index 4cc4f3d845e..547e4cdd379 100644
--- a/gcc/cp/mapper-client.h
+++ b/gcc/cp/mapper-client.h
@@ -57,6 +57,7 @@ public:
   static module_client *open_module_client (location_t loc, const char *option,
                                            class mkdeps *,
                                            void (*set_repo) (const char *),
+                                           char const *,
                                            char const *);
   static void close_module_client (location_t loc, module_client *);
 };
diff --git a/gcc/cp/mapper-client.cc b/gcc/cp/mapper-client.cc
index fbe52814cb9..ff70eae455d 100644
--- a/gcc/cp/mapper-client.cc
+++ b/gcc/cp/mapper-client.cc
@@ -136,6 +136,7 @@ module_client *
 module_client::open_module_client (location_t loc, const char *o,
                                   class mkdeps *deps,
                                   void (*set_repo) (const char *),
+                                  char const *default_suffix,
                                   char const *full_program_name)
 {
   module_client *c = nullptr;
@@ -302,7 +303,16 @@ module_client::open_module_client (location_t loc, const 
char *o,
          }
        }
       else
-       r->set_repo ("gcm.cache");
+       {
+         std::string rp = "gcm.cache";
+         if (default_suffix)
+           {
+             gcc_assert (strlen (default_suffix));
+             rp += '/';
+             rp += default_suffix;
+           }
+         r->set_repo (std::move (rp));
+       }
 
       auto *s = new Cody::Server (r);
       c = new module_client (s);
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 9bf44c03c2d..cf7d38c9f5d 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -14597,8 +14597,12 @@ make_mapper (location_t loc, class mkdeps *deps)
   if (!option)
     option = getenv ("CXX_MODULE_MAPPER");
 
+  const char *suffix = nullptr;
+  if (flag_module_repo_dialect)
+    suffix = get_cxx_dialect_name (cxx_dialect);
+
   mapper = module_client::open_module_client
-    (loc, option, deps, &set_cmi_repo,
+    (loc, option, deps, &set_cmi_repo, suffix,
      (save_decoded_options[0].opt_index == OPT_SPECIAL_program_name)
      && save_decoded_options[0].arg != progname
      ? save_decoded_options[0].arg : nullptr);
diff --git a/gcc/testsuite/g++.dg/modules/modules.exp 
b/gcc/testsuite/g++.dg/modules/modules.exp
index e6bf28d8b1a..3ae647eb96e 100644
--- a/gcc/testsuite/g++.dg/modules/modules.exp
+++ b/gcc/testsuite/g++.dg/modules/modules.exp
@@ -36,7 +36,12 @@ if ![info exists DEFAULT_CXXFLAGS] then {
     set DEFAULT_CXXFLAGS " -pedantic-errors -Wno-long-long"
 }
 set DEFAULT_MODFLAGS $DEFAULT_CXXFLAGS
-set MOD_STD_LIST { 17 2a 2b }
+set MOD_STD_LIST { 20 23 26 }
+
+# Put gcms directly in gcm.cache so dg-module-cmi can find them.
+global ALWAYS_CXXFLAGS
+set save_ALWAYS $ALWAYS_CXXFLAGS
+lappend ALWAYS_CXXFLAGS "additional_flags=-fno-module-repo-dialect"
 
 dg-init
 
@@ -425,4 +430,6 @@ foreach src [lsort [find $srcdir/$subdir {*_a.[CHX}]] {
 rename unsupported {}
 rename modules-saved-unsupported unsupported
 
+set ALWAYS_CXXFLAGS $save_ALWAYS
+
 dg-finish

base-commit: 7b8b96a327f2201531c0a2b32db490532db4aa39
-- 
2.47.0

Reply via email to