[clang] [clang][modules-driver] Add support for C++ named modules and `import std` (PR #193312)
Naveen Seth Hanig via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 22 02:05:03 PDT 2026
================
@@ -1506,6 +1518,80 @@ static void createAndConnectRoot(CompilationGraph &Graph) {
}
}
+/// Creates a temporary output path for \p ModuleName.
+static std::string createModuleOutputPath(const Compilation &C,
+ StringRef ModuleName) {
+ // Sanitize the ':' included in parition names. It is illegal for filenames on
+ // Windows.
+ SmallString<32> SanitizedModuleName(ModuleName);
+ llvm::replace(SanitizedModuleName, ':', '_');
+ auto ModuleOutputPath = C.getDriver().GetTemporaryPath(
+ SanitizedModuleName, types::getTypeTempSuffix(types::TY_ModuleFile));
+ return ModuleOutputPath;
+}
+
+/// Adds arguments to output the module produced by \p Node at \p OutputPath.
+static void configureNamedModuleOutputArgs(Compilation &C,
+ NamedModuleJobNode &Node,
+ StringRef ModuleOutputPath) {
+ auto &Job = *Node.Job;
+ const auto &TCArgs = getToolChainArgs(C, Job);
+ auto JobArgs = Job.getArguments();
+
+ JobArgs.push_back(
+ TCArgs.MakeArgString("-fmodule-output=" + ModuleOutputPath));
+ // Ensure that this job will emit a module. If the main input for this job
+ // is not of types::CXXModule, we need to explicitly add this.
----------------
naveen-seth wrote:
Do you mean we should not support exporting modules from `.cpp` files, and instead only allow exports from `.cppm` files?
I would strongly prefer that as well, since supporting exports from `.cpp` would make future support for `-fno-modules-reduced-bmi` much harder and also makes maintenance more complex overall.
https://github.com/llvm/llvm-project/pull/193312
More information about the cfe-commits
mailing list