Skip to content

Commit 27c02e0

Browse files
committed
Revert "Reland [clang][modules-driver] Add scanner to detect C++20 module presence (llvm#153497)"
This reverts commit 9403c2d. During the review of llvm#152770, it was decided to remove the logic that would have been used to implicitly enable the -fmodules-driver feature in the future. (Currently, this logic is only used for diagnostics.) If we find that implicitly enabling the -fmodules-driver feature is really useful in practice later on, it may be re-added. Link to review comment: llvm#152770 (comment)
1 parent 1e4a54b commit 27c02e0

File tree

9 files changed

+4
-385
lines changed

9 files changed

+4
-385
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -581,13 +581,6 @@ def err_drv_reduced_module_output_overrided : Warning<
581581
"please consider use '-fmodule-output=' to specify the output file for reduced BMI explicitly">,
582582
InGroup<DiagGroup<"reduced-bmi-output-overrided">>;
583583

584-
def remark_found_cxx20_module_usage : Remark<
585-
"found C++20 module usage in file '%0'">,
586-
InGroup<ModulesDriver>;
587-
def remark_performing_driver_managed_module_build : Remark<
588-
"performing driver managed module build">,
589-
InGroup<ModulesDriver>;
590-
591584
def warn_drv_delayed_template_parsing_after_cxx20 : Warning<
592585
"-fdelayed-template-parsing is deprecated after C++20">,
593586
InGroup<DiagGroup<"delayed-template-parsing-in-cxx20">>;

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,6 @@ def ModuleConflict : DiagGroup<"module-conflict">;
636636
def ModuleFileExtension : DiagGroup<"module-file-extension">;
637637
def ModuleIncludeDirectiveTranslation : DiagGroup<"module-include-translation">;
638638
def ModuleMap : DiagGroup<"module-map">;
639-
def ModulesDriver : DiagGroup<"modules-driver">;
640639
def RoundTripCC1Args : DiagGroup<"round-trip-cc1-args">;
641640
def NewlineEOF : DiagGroup<"newline-eof">;
642641
def Nullability : DiagGroup<"nullability">;

clang/include/clang/Driver/Driver.h

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,6 @@ class Driver {
512512

513513
/// BuildActions - Construct the list of actions to perform for the
514514
/// given arguments, which are only done for a single architecture.
515-
/// If the compilation is an explicit module build, delegates to
516-
/// BuildDriverManagedModuleBuildActions. Otherwise, BuildDefaultActions is
517-
/// used.
518515
///
519516
/// \param C - The compilation that is being built.
520517
/// \param Args - The input arguments.
@@ -799,35 +796,6 @@ class Driver {
799796
/// compilation based on which -f(no-)?lto(=.*)? option occurs last.
800797
void setLTOMode(const llvm::opt::ArgList &Args);
801798

802-
/// BuildDefaultActions - Constructs the list of actions to perform
803-
/// for the provided arguments, which are only done for a single architecture.
804-
///
805-
/// \param C - The compilation that is being built.
806-
/// \param Args - The input arguments.
807-
/// \param Actions - The list to store the resulting actions onto.
808-
void BuildDefaultActions(Compilation &C, llvm::opt::DerivedArgList &Args,
809-
const InputList &Inputs, ActionList &Actions) const;
810-
811-
/// BuildDriverManagedModuleBuildActions - Performs a dependency
812-
/// scan and constructs the list of actions to perform for dependency order
813-
/// and the provided arguments. This is only done for a single a architecture.
814-
///
815-
/// \param C - The compilation that is being built.
816-
/// \param Args - The input arguments.
817-
/// \param Actions - The list to store the resulting actions onto.
818-
void BuildDriverManagedModuleBuildActions(Compilation &C,
819-
llvm::opt::DerivedArgList &Args,
820-
const InputList &Inputs,
821-
ActionList &Actions) const;
822-
823-
/// Scans the leading lines of the C++ source inputs to detect C++20 module
824-
/// usage.
825-
///
826-
/// \returns True if module usage is detected, false otherwise, or an error on
827-
/// read failure.
828-
llvm::ErrorOr<bool>
829-
ScanInputsForCXX20ModulesUsage(const InputList &Inputs) const;
830-
831799
/// Retrieves a ToolChain for a particular \p Target triple.
832800
///
833801
/// Will cache ToolChains for the life of the driver object, and create them

clang/include/clang/Driver/Options.td

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3342,13 +3342,6 @@ defm modules_reduced_bmi : BoolOption<"f", "modules-reduced-bmi",
33423342
PosFlag<SetTrue, [], [ClangOption, CC1Option],
33433343
"Generate the reduced BMI">>;
33443344

3345-
def fmodules_driver : Flag<["-"], "fmodules-driver">,
3346-
Group<f_Group>, Visibility<[ClangOption]>,
3347-
HelpText<"Enable support for driver managed module builds (experimental)">;
3348-
def fno_modules_driver : Flag<["-"], "fno-modules-driver">,
3349-
Group<f_Group>, Visibility<[ClangOption]>,
3350-
HelpText<"Disable support for driver managed module builds (experimental)">;
3351-
33523345
def experimental_modules_reduced_bmi : Flag<["-"], "fexperimental-modules-reduced-bmi">,
33533346
Group<f_Group>, Visibility<[ClangOption, CC1Option]>, Alias<fmodules_reduced_bmi>;
33543347

clang/include/clang/Lex/DependencyDirectivesScanner.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,6 @@ void printDependencyDirectivesAsSource(
135135
ArrayRef<dependency_directives_scan::Directive> Directives,
136136
llvm::raw_ostream &OS);
137137

138-
/// Scan an input source buffer for C++20 named module usage.
139-
///
140-
/// \param Source The input source buffer.
141-
///
142-
/// \returns true if any C++20 named modules related directive was found.
143-
bool scanInputForCXX20ModulesUsage(StringRef Source);
144-
145138
/// Functor that returns the dependency directives for a given file.
146139
class DependencyDirectivesGetter {
147140
public:

clang/lib/Driver/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,5 @@ add_clang_library(clangDriver
9898

9999
LINK_LIBS
100100
clangBasic
101-
clangLex
102101
${system_libs}
103102
)

clang/lib/Driver/Driver.cpp

Lines changed: 4 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
#include "clang/Driver/Tool.h"
6767
#include "clang/Driver/ToolChain.h"
6868
#include "clang/Driver/Types.h"
69-
#include "clang/Lex/DependencyDirectivesScanner.h"
7069
#include "llvm/ADT/ArrayRef.h"
7170
#include "llvm/ADT/STLExtras.h"
7271
#include "llvm/ADT/SmallSet.h"
@@ -4189,11 +4188,6 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
41894188
YcArg = nullptr;
41904189
}
41914190

4192-
if (Args.hasArgNoClaim(options::OPT_fmodules_driver))
4193-
// TODO: Check against all incompatible -fmodules-driver arguments
4194-
if (!ModulesModeCXX20 && !Args.hasArgNoClaim(options::OPT_fmodules))
4195-
Args.eraseArg(options::OPT_fmodules_driver);
4196-
41974191
Arg *FinalPhaseArg;
41984192
phases::ID FinalPhase = getFinalPhase(Args, &FinalPhaseArg);
41994193

@@ -4320,33 +4314,6 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
43204314
}
43214315
}
43224316

4323-
static bool hasCXXModuleInputType(const Driver::InputList &Inputs) {
4324-
const auto IsTypeCXXModule = [](const auto &Input) -> bool {
4325-
const auto TypeID = Input.first;
4326-
return (TypeID == types::TY_CXXModule);
4327-
};
4328-
return llvm::any_of(Inputs, IsTypeCXXModule);
4329-
}
4330-
4331-
llvm::ErrorOr<bool>
4332-
Driver::ScanInputsForCXX20ModulesUsage(const InputList &Inputs) const {
4333-
const auto CXXInputs = llvm::make_filter_range(
4334-
Inputs, [](const auto &Input) { return types::isCXX(Input.first); });
4335-
for (const auto &Input : CXXInputs) {
4336-
StringRef Filename = Input.second->getSpelling();
4337-
auto ErrOrBuffer = VFS->getBufferForFile(Filename);
4338-
if (!ErrOrBuffer)
4339-
return ErrOrBuffer.getError();
4340-
const auto Buffer = std::move(*ErrOrBuffer);
4341-
4342-
if (scanInputForCXX20ModulesUsage(Buffer->getBuffer())) {
4343-
Diags.Report(diag::remark_found_cxx20_module_usage) << Filename;
4344-
return true;
4345-
}
4346-
}
4347-
return false;
4348-
}
4349-
43504317
void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
43514318
const InputList &Inputs, ActionList &Actions) const {
43524319
llvm::PrettyStackTraceString CrashInfo("Building compilation actions");
@@ -4358,33 +4325,6 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
43584325

43594326
handleArguments(C, Args, Inputs, Actions);
43604327

4361-
if (Args.hasFlag(options::OPT_fmodules_driver,
4362-
options::OPT_fno_modules_driver, false)) {
4363-
// TODO: Move the logic for implicitly enabling explicit-module-builds out
4364-
// of -fmodules-driver once it is no longer experimental.
4365-
// Currently, this serves diagnostic purposes only.
4366-
bool UsesCXXModules = hasCXXModuleInputType(Inputs);
4367-
if (!UsesCXXModules) {
4368-
const auto ErrOrScanResult = ScanInputsForCXX20ModulesUsage(Inputs);
4369-
if (!ErrOrScanResult) {
4370-
Diags.Report(diag::err_cannot_open_file)
4371-
<< ErrOrScanResult.getError().message();
4372-
return;
4373-
}
4374-
UsesCXXModules = *ErrOrScanResult;
4375-
}
4376-
if (UsesCXXModules || Args.hasArg(options::OPT_fmodules))
4377-
BuildDriverManagedModuleBuildActions(C, Args, Inputs, Actions);
4378-
return;
4379-
}
4380-
4381-
BuildDefaultActions(C, Args, Inputs, Actions);
4382-
}
4383-
4384-
void Driver::BuildDefaultActions(Compilation &C, DerivedArgList &Args,
4385-
const InputList &Inputs,
4386-
ActionList &Actions) const {
4387-
43884328
bool UseNewOffloadingDriver =
43894329
C.isOffloadingHostKind(Action::OFK_OpenMP) ||
43904330
C.isOffloadingHostKind(Action::OFK_SYCL) ||
@@ -4642,28 +4582,16 @@ void Driver::BuildDefaultActions(Compilation &C, DerivedArgList &Args,
46424582
}
46434583
}
46444584

4585+
// Call validator for dxil when -Vd not in Args.
46454586
if (C.getDefaultToolChain().getTriple().isDXIL()) {
4587+
// Only add action when needValidation.
46464588
const auto &TC =
46474589
static_cast<const toolchains::HLSLToolChain &>(C.getDefaultToolChain());
4648-
4649-
// Call objcopy for manipulation of the unvalidated DXContainer when an
4650-
// option in Args requires it.
4651-
if (TC.requiresObjcopy(Args)) {
4652-
Action *LastAction = Actions.back();
4653-
// llvm-objcopy expects an unvalidated DXIL container (TY_OBJECT).
4654-
if (LastAction->getType() == types::TY_Object)
4655-
Actions.push_back(
4656-
C.MakeAction<ObjcopyJobAction>(LastAction, types::TY_Object));
4657-
}
4658-
4659-
// Call validator for dxil when -Vd not in Args.
46604590
if (TC.requiresValidation(Args)) {
46614591
Action *LastAction = Actions.back();
46624592
Actions.push_back(C.MakeAction<BinaryAnalyzeJobAction>(
46634593
LastAction, types::TY_DX_CONTAINER));
46644594
}
4665-
4666-
// Call metal-shaderconverter when targeting metal.
46674595
if (TC.requiresBinaryTranslation(Args)) {
46684596
Action *LastAction = Actions.back();
46694597
// Metal shader converter runs on DXIL containers, which can either be
@@ -4680,12 +4608,6 @@ void Driver::BuildDefaultActions(Compilation &C, DerivedArgList &Args,
46804608
Args.ClaimAllArgs(options::OPT_cl_ignored_Group);
46814609
}
46824610

4683-
void Driver::BuildDriverManagedModuleBuildActions(
4684-
Compilation &C, llvm::opt::DerivedArgList &Args, const InputList &Inputs,
4685-
ActionList &Actions) const {
4686-
Diags.Report(diag::remark_performing_driver_managed_module_build);
4687-
}
4688-
46894611
/// Returns the canonical name for the offloading architecture when using a HIP
46904612
/// or CUDA architecture.
46914613
static StringRef getCanonicalArchString(Compilation &C,
@@ -6265,9 +6187,8 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
62656187
C.getArgs().hasArg(options::OPT_dxc_Fo)) ||
62666188
JA.getType() == types::TY_DX_CONTAINER) {
62676189
StringRef FoValue = C.getArgs().getLastArgValue(options::OPT_dxc_Fo);
6268-
// If we are targeting DXIL and not validating/translating/objcopying, we
6269-
// should set the final result file. Otherwise we should emit to a
6270-
// temporary.
6190+
// If we are targeting DXIL and not validating or translating, we should set
6191+
// the final result file. Otherwise we should emit to a temporary.
62716192
if (C.getDefaultToolChain().getTriple().isDXIL()) {
62726193
const auto &TC = static_cast<const toolchains::HLSLToolChain &>(
62736194
C.getDefaultToolChain());
@@ -6613,9 +6534,6 @@ std::string Driver::GetStdModuleManifestPath(const Compilation &C,
66136534
const ToolChain &TC) const {
66146535
std::string error = "<NOT PRESENT>";
66156536

6616-
if (C.getArgs().hasArg(options::OPT_nostdlib))
6617-
return error;
6618-
66196537
switch (TC.GetCXXStdlibType(C.getArgs())) {
66206538
case ToolChain::CST_Libcxx: {
66216539
auto evaluate = [&](const char *library) -> std::optional<std::string> {
@@ -6836,8 +6754,6 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
68366754
TC = std::make_unique<toolchains::VEToolChain>(*this, Target, Args);
68376755
else if (Target.isOHOSFamily())
68386756
TC = std::make_unique<toolchains::OHOS>(*this, Target, Args);
6839-
else if (Target.isWALI())
6840-
TC = std::make_unique<toolchains::WebAssembly>(*this, Target, Args);
68416757
else
68426758
TC = std::make_unique<toolchains::Linux>(*this, Target, Args);
68436759
break;

clang/lib/Lex/DependencyDirectivesScanner.cpp

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ struct Scanner {
8383
/// \returns True on error.
8484
bool scan(SmallVectorImpl<Directive> &Directives);
8585

86-
friend bool clang::scanInputForCXX20ModulesUsage(StringRef Source);
87-
8886
private:
8987
/// Lexes next token and advances \p First and the \p Lexer.
9088
[[nodiscard]] dependency_directives_scan::Token &
@@ -1077,51 +1075,3 @@ void clang::printDependencyDirectivesAsSource(
10771075
}
10781076
}
10791077
}
1080-
1081-
static void skipUntilMaybeCXX20ModuleDirective(const char *&First,
1082-
const char *const End) {
1083-
assert(First <= End);
1084-
while (First != End) {
1085-
if (*First == '#') {
1086-
++First;
1087-
skipToNewlineRaw(First, End);
1088-
}
1089-
skipWhitespace(First, End);
1090-
if (const auto Len = isEOL(First, End)) {
1091-
First += Len;
1092-
continue;
1093-
}
1094-
break;
1095-
}
1096-
}
1097-
1098-
bool clang::scanInputForCXX20ModulesUsage(StringRef Source) {
1099-
const char *First = Source.begin();
1100-
const char *const End = Source.end();
1101-
skipUntilMaybeCXX20ModuleDirective(First, End);
1102-
if (First == End)
1103-
return false;
1104-
1105-
// Check if the next token can even be a module directive before creating a
1106-
// full lexer.
1107-
if (!(*First == 'i' || *First == 'e' || *First == 'm'))
1108-
return false;
1109-
1110-
llvm::SmallVector<dependency_directives_scan::Token> Tokens;
1111-
Scanner S(StringRef(First, End - First), Tokens, nullptr, SourceLocation());
1112-
S.TheLexer.setParsingPreprocessorDirective(true);
1113-
if (S.lexModule(First, End))
1114-
return false;
1115-
auto IsCXXNamedModuleDirective = [](const DirectiveWithTokens &D) {
1116-
switch (D.Kind) {
1117-
case dependency_directives_scan::cxx_module_decl:
1118-
case dependency_directives_scan::cxx_import_decl:
1119-
case dependency_directives_scan::cxx_export_module_decl:
1120-
case dependency_directives_scan::cxx_export_import_decl:
1121-
return true;
1122-
default:
1123-
return false;
1124-
}
1125-
};
1126-
return llvm::any_of(S.DirsWithToks, IsCXXNamedModuleDirective);
1127-
}

0 commit comments

Comments
 (0)