Skip to content

Commit 0bdcf4e

Browse files
authored
Revert "Reapply "[clang][modules-driver] Add support for C++ named modules and import std" (#193857)
Reverts #193815 due to a test failure (`clang/test/Driver/modules-driver-import-std.cpp`) on some systems.
1 parent 0d1bf3a commit 0bdcf4e

8 files changed

Lines changed: 11 additions & 366 deletions

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,6 @@ def err_drv_reduced_module_output_overrided : Warning<
613613
"please consider use '-fmodule-output=' to specify the output file for reduced BMI explicitly">,
614614
InGroup<DiagGroup<"reduced-bmi-output-overrided">>;
615615

616-
def err_drv_modules_driver_requires_reduced_bmi : Error<
617-
"'-fmodules-driver' is currently incompatible with '-fno-modules-reduced-bmi'">;
618616
def remark_performing_driver_managed_module_build : Remark<
619617
"performing driver managed module build">, InGroup<ModulesDriver>;
620618
def remark_modules_manifest_not_found : Remark<

clang/include/clang/Driver/ModulesDriver.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ class Compilation;
3232

3333
namespace clang::driver::modules {
3434

35-
/// Emits diagnostics for arguments incompatible with -fmodules-driver.
36-
void diagnoseModulesDriverArgs(llvm::opt::DerivedArgList &DAL,
37-
DiagnosticsEngine &Diags);
38-
3935
/// The parsed Standard library module manifest.
4036
struct StdModuleManifest {
4137
struct Module {

clang/lib/Driver/Driver.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,8 +1837,6 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
18371837
if (UseModulesDriver) {
18381838
Diags.Report(diag::remark_performing_driver_managed_module_build);
18391839

1840-
modules::diagnoseModulesDriverArgs(C->getArgs(), Diags);
1841-
18421840
// Read the Standard library module manifest and, if available, add all
18431841
// discovered modules to this Compilation. Jobs for modules specified in
18441842
// the manifest that are not required by any command-line input are pruned

clang/lib/Driver/ModulesDriver.cpp

Lines changed: 11 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "clang/Driver/Job.h"
2222
#include "clang/Driver/Tool.h"
2323
#include "clang/Driver/ToolChain.h"
24-
#include "clang/Driver/Types.h"
2524
#include "clang/Frontend/StandaloneDiagnostic.h"
2625
#include "llvm/ADT/DenseSet.h"
2726
#include "llvm/ADT/DepthFirstIterator.h"
@@ -48,14 +47,6 @@ using namespace clang;
4847
using namespace driver;
4948
using namespace modules;
5049

51-
void driver::modules::diagnoseModulesDriverArgs(llvm::opt::DerivedArgList &DAL,
52-
DiagnosticsEngine &Diags) {
53-
if (!DAL.hasFlag(options::OPT_fmodules_reduced_bmi,
54-
options::OPT_fno_modules_reduced_bmi, true)) {
55-
Diags.Report(diag::err_drv_modules_driver_requires_reduced_bmi);
56-
}
57-
}
58-
5950
namespace clang::driver::modules {
6051
static bool fromJSON(const llvm::json::Value &Params,
6152
StdModuleManifest::Module::LocalArguments &LocalArgs,
@@ -1261,16 +1252,6 @@ static SmallVector<JobNode *> createNodesForUnusedStdlibModuleJobs(
12611252
return StdlibModuleNodesToPrune;
12621253
}
12631254

1264-
// Returns the derived argument list for the tool chain responsible
1265-
// for creating \p Job.
1266-
static const DerivedArgList &getToolChainArgs(Compilation &C,
1267-
const Command &Job) {
1268-
const auto &TC = Job.getCreator().getToolChain();
1269-
const auto &SourceAction = Job.getSource();
1270-
return C.getArgsForToolChain(&TC, SourceAction.getOffloadingArch(),
1271-
SourceAction.getOffloadingDeviceKind());
1272-
}
1273-
12741255
/// Creates a job for the Clang module described by \p MD.
12751256
static std::unique_ptr<Command>
12761257
createClangModulePrecompileJob(Compilation &C, const Command &ImportingJob,
@@ -1282,7 +1263,9 @@ createClangModulePrecompileJob(Compilation &C, const Command &ImportingJob,
12821263
Action *PA = C.MakeAction<PrecompileJobAction>(IA, types::ID::TY_ModuleFile);
12831264
PA->propagateOffloadInfo(&ImportingJob.getSource());
12841265

1285-
const auto &TCArgs = getToolChainArgs(C, ImportingJob);
1266+
const auto &TC = ImportingJob.getCreator().getToolChain();
1267+
const auto &TCArgs = C.getArgsForToolChain(&TC, PA->getOffloadingArch(),
1268+
PA->getOffloadingDeviceKind());
12861269

12871270
const auto &BuildArgs = MD.getBuildArguments();
12881271
ArgStringList JobArgs;
@@ -1336,7 +1319,12 @@ installScanCommandLines(Compilation &C,
13361319
ArgStringList JobArgs;
13371320
JobArgs.reserve(BuildArgs.size());
13381321

1339-
auto &TCArgs = getToolChainArgs(C, Job);
1322+
const auto &SourceAction = Job.getSource();
1323+
const auto &TC = Job.getCreator().getToolChain();
1324+
auto &TCArgs =
1325+
C.getArgsForToolChain(&TC, SourceAction.getOffloadingArch(),
1326+
SourceAction.getOffloadingDeviceKind());
1327+
13401328
for (const auto &Arg : BuildArgs)
13411329
JobArgs.push_back(TCArgs.MakeArgString(Arg));
13421330

@@ -1539,73 +1527,6 @@ static void createAndConnectRoot(CompilationGraph &Graph) {
15391527
}
15401528
}
15411529

1542-
/// Creates a temporary output path for \p ModuleName.
1543-
static std::string createModuleOutputPath(const Compilation &C,
1544-
StringRef ModuleName) {
1545-
// Sanitize the ':' included in parition names. It is illegal for filenames on
1546-
// Windows.
1547-
SmallString<32> SanitizedModuleName(ModuleName);
1548-
llvm::replace(SanitizedModuleName, ':', '-');
1549-
auto ModuleOutputPath = C.getDriver().GetTemporaryPath(
1550-
SanitizedModuleName, types::getTypeTempSuffix(types::TY_ModuleFile));
1551-
return ModuleOutputPath;
1552-
}
1553-
1554-
/// Adds the '-fmodule-output=' argument for the module produced by \p Node.
1555-
static void configureNamedModuleOutputArg(Compilation &C,
1556-
NamedModuleJobNode &Node,
1557-
StringRef ModuleOutputPath) {
1558-
auto &Job = *Node.Job;
1559-
const auto &TCArgs = getToolChainArgs(C, Job);
1560-
auto JobArgs = Job.getArguments();
1561-
JobArgs.push_back(
1562-
TCArgs.MakeArgString("-fmodule-output=" + ModuleOutputPath));
1563-
Job.replaceArguments(std::move(JobArgs));
1564-
}
1565-
1566-
/// Propagates the '-fmodule-file=' mapping for the named module described by
1567-
/// \p Node to each dependent job.
1568-
static void propagateModuleFileMappingArg(Compilation &C,
1569-
NamedModuleJobNode &Node,
1570-
StringRef ModuleOutputPath) {
1571-
const StringRef ModuleName = Node.InputDeps.ModuleName;
1572-
1573-
auto DependentNodes = llvm::drop_begin(llvm::depth_first<CGNode *>(&Node));
1574-
auto DependentScannedNodes = llvm::map_range(
1575-
llvm::make_filter_range(DependentNodes, llvm::IsaPred<ScannedJobNode>),
1576-
llvm::CastTo<ScannedJobNode>);
1577-
1578-
for (ScannedJobNode *DependentNode : DependentScannedNodes) {
1579-
auto &DependentJob = *DependentNode->Job;
1580-
const auto &TCArgs = getToolChainArgs(C, DependentJob);
1581-
auto JobArgs = DependentJob.getArguments();
1582-
JobArgs.push_back(TCArgs.MakeArgString("-fmodule-file=" + ModuleName + "=" +
1583-
ModuleOutputPath));
1584-
DependentJob.replaceArguments(std::move(JobArgs));
1585-
}
1586-
}
1587-
1588-
/// Finalizes command lines for C++20 named module dependencies.
1589-
///
1590-
/// The command lines produced by dependency scanning are only adjusted to
1591-
/// handle discovered Clang modules. For C++20 named modules, we update the
1592-
/// command-lines here.
1593-
static void fixupNamedModuleCommandLines(Compilation &C,
1594-
CompilationGraph &Graph) {
1595-
const auto NamedModuleNodes = llvm::map_range(
1596-
llvm::make_filter_range(Graph, llvm::IsaPred<NamedModuleJobNode>),
1597-
llvm::CastTo<NamedModuleJobNode>);
1598-
1599-
for (NamedModuleJobNode *Node : NamedModuleNodes) {
1600-
const StringRef ModuleName = Node->InputDeps.ModuleName;
1601-
const auto ModuleOutputPath = createModuleOutputPath(C, ModuleName);
1602-
C.addTempFile(C.getArgs().MakeArgString(ModuleOutputPath));
1603-
1604-
configureNamedModuleOutputArg(C, *Node, ModuleOutputPath);
1605-
propagateModuleFileMappingArg(C, *Node, ModuleOutputPath);
1606-
}
1607-
}
1608-
16091530
/// Moves jobs from \p Graph into \p C in the graph's topological order.
16101531
static void feedJobsBackIntoCompilation(Compilation &C,
16111532
CompilationGraph &&Graph) {
@@ -1679,6 +1600,7 @@ void driver::modules::runModulesDriver(
16791600
if (!Diags.isLastDiagnosticIgnored())
16801601
llvm::WriteGraph<const CompilationGraph *>(llvm::errs(), &Graph);
16811602

1682-
fixupNamedModuleCommandLines(C, Graph);
1603+
// TODO: Fix-up command-lines for named module imports.
1604+
16831605
feedJobsBackIntoCompilation(C, std::move(Graph));
16841606
}

clang/test/Driver/modules-driver-both-modules-types.cpp

Lines changed: 0 additions & 111 deletions
This file was deleted.

clang/test/Driver/modules-driver-cxx-modules-only.cpp

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)