Skip to content

Commit 7223bb1

Browse files
naveen-sethmahesh-attarde
authored andcommitted
Revert "Reland [clang][modules-driver] Add scanner to detect C++20 module presence" (llvm#149900)
Reverts llvm#147630. This causes a linker error caused by linking the driver against the lexer.
1 parent e0dc48b commit 7223bb1

File tree

8 files changed

+0
-365
lines changed

8 files changed

+0
-365
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

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

580-
def remark_found_cxx20_module_usage : Remark<
581-
"found C++20 module usage in file '%0'">,
582-
InGroup<ModulesDriver>;
583-
def remark_performing_driver_managed_module_build : Remark<
584-
"performing driver managed module build">,
585-
InGroup<ModulesDriver>;
586-
587580
def warn_drv_delayed_template_parsing_after_cxx20 : Warning<
588581
"-fdelayed-template-parsing is deprecated after C++20">,
589582
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
@@ -628,7 +628,6 @@ def ModuleConflict : DiagGroup<"module-conflict">;
628628
def ModuleFileExtension : DiagGroup<"module-file-extension">;
629629
def ModuleIncludeDirectiveTranslation : DiagGroup<"module-include-translation">;
630630
def ModuleMap : DiagGroup<"module-map">;
631-
def ModulesDriver : DiagGroup<"modules-driver">;
632631
def RoundTripCC1Args : DiagGroup<"round-trip-cc1-args">;
633632
def NewlineEOF : DiagGroup<"newline-eof">;
634633
def Nullability : DiagGroup<"nullability">;

clang/include/clang/Driver/Driver.h

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

505505
/// BuildActions - Construct the list of actions to perform for the
506506
/// given arguments, which are only done for a single architecture.
507-
/// If the compilation is an explicit module build, delegates to
508-
/// BuildDriverManagedModuleBuildActions. Otherwise, BuildDefaultActions is
509-
/// used.
510507
///
511508
/// \param C - The compilation that is being built.
512509
/// \param Args - The input arguments.
@@ -792,35 +789,6 @@ class Driver {
792789
/// compilation based on which -f(no-)?lto(=.*)? option occurs last.
793790
void setLTOMode(const llvm::opt::ArgList &Args);
794791

795-
/// BuildDefaultActions - Constructs the list of actions to perform
796-
/// for the provided arguments, which are only done for a single architecture.
797-
///
798-
/// \param C - The compilation that is being built.
799-
/// \param Args - The input arguments.
800-
/// \param Actions - The list to store the resulting actions onto.
801-
void BuildDefaultActions(Compilation &C, llvm::opt::DerivedArgList &Args,
802-
const InputList &Inputs, ActionList &Actions) const;
803-
804-
/// BuildDriverManagedModuleBuildActions - Performs a dependency
805-
/// scan and constructs the list of actions to perform for dependency order
806-
/// and the provided arguments. This is only done for a single a architecture.
807-
///
808-
/// \param C - The compilation that is being built.
809-
/// \param Args - The input arguments.
810-
/// \param Actions - The list to store the resulting actions onto.
811-
void BuildDriverManagedModuleBuildActions(Compilation &C,
812-
llvm::opt::DerivedArgList &Args,
813-
const InputList &Inputs,
814-
ActionList &Actions) const;
815-
816-
/// Scans the leading lines of the C++ source inputs to detect C++20 module
817-
/// usage.
818-
///
819-
/// \returns True if module usage is detected, false otherwise, or an error on
820-
/// read failure.
821-
llvm::ErrorOr<bool>
822-
ScanInputsForCXX20ModulesUsage(const InputList &Inputs) const;
823-
824792
/// Retrieves a ToolChain for a particular \p Target triple.
825793
///
826794
/// 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
@@ -3263,13 +3263,6 @@ defm modules_reduced_bmi : BoolOption<"f", "modules-reduced-bmi",
32633263
PosFlag<SetTrue, [], [ClangOption, CC1Option],
32643264
"Generate the reduced BMI">>;
32653265

3266-
def fmodules_driver : Flag<["-"], "fmodules-driver">,
3267-
Group<f_Group>, Visibility<[ClangOption]>,
3268-
HelpText<"Enable support for driver managed module builds (experimental)">;
3269-
def fno_modules_driver : Flag<["-"], "fno-modules-driver">,
3270-
Group<f_Group>, Visibility<[ClangOption]>,
3271-
HelpText<"Disable support for driver managed module builds (experimental)">;
3272-
32733266
def experimental_modules_reduced_bmi : Flag<["-"], "fexperimental-modules-reduced-bmi">,
32743267
Group<f_Group>, Visibility<[ClangOption, CC1Option]>, Alias<fmodules_reduced_bmi>;
32753268

clang/include/clang/Lex/DependencyDirectivesScanner.h

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

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

clang/lib/Driver/Driver.cpp

Lines changed: 0 additions & 70 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/StringExtras.h"
@@ -4291,12 +4290,6 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
42914290
YcArg = nullptr;
42924291
}
42934292

4294-
if (Args.hasArgNoClaim(options::OPT_fmodules_driver))
4295-
// TODO: Check against all incompatible -fmodules-driver arguments
4296-
if (!ModulesModeCXX20) {
4297-
Args.eraseArg(options::OPT_fmodules_driver);
4298-
}
4299-
43004293
Arg *FinalPhaseArg;
43014294
phases::ID FinalPhase = getFinalPhase(Args, &FinalPhaseArg);
43024295

@@ -4423,35 +4416,6 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
44234416
}
44244417
}
44254418

4426-
static bool hasCXXModuleInputType(const Driver::InputList &Inputs) {
4427-
const auto IsTypeCXXModule = [](const auto &Input) -> bool {
4428-
const auto TypeID = Input.first;
4429-
return (TypeID == types::TY_CXXModule);
4430-
};
4431-
return llvm::any_of(Inputs, IsTypeCXXModule);
4432-
}
4433-
4434-
llvm::ErrorOr<bool>
4435-
Driver::ScanInputsForCXX20ModulesUsage(const InputList &Inputs) const {
4436-
const auto CXXInputs = llvm::make_filter_range(
4437-
Inputs, [](const auto &Input) { return types::isCXX(Input.first); });
4438-
4439-
for (const auto &Input : CXXInputs) {
4440-
StringRef Filename = Input.second->getSpelling();
4441-
auto ErrOrBuffer = VFS->getBufferForFile(Filename);
4442-
if (!ErrOrBuffer)
4443-
return ErrOrBuffer.getError();
4444-
const auto Buffer = std::move(*ErrOrBuffer);
4445-
4446-
if (scanInputForCXX20ModulesUsage(Buffer->getBuffer())) {
4447-
Diags.Report(diag::remark_found_cxx20_module_usage) << Filename;
4448-
return true;
4449-
}
4450-
}
4451-
4452-
return false;
4453-
}
4454-
44554419
void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
44564420
const InputList &Inputs, ActionList &Actions) const {
44574421
llvm::PrettyStackTraceString CrashInfo("Building compilation actions");
@@ -4463,33 +4427,6 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
44634427

44644428
handleArguments(C, Args, Inputs, Actions);
44654429

4466-
if (Args.hasFlag(options::OPT_fmodules_driver,
4467-
options::OPT_fno_modules_driver, false)) {
4468-
// TODO: Move the logic for implicitly enabling explicit-module-builds out
4469-
// of -fmodules-driver once it is no longer experimental.
4470-
// Currently, this serves diagnostic purposes only.
4471-
bool UsesCXXModules = hasCXXModuleInputType(Inputs);
4472-
if (!UsesCXXModules) {
4473-
const auto ErrOrScanResult = ScanInputsForCXX20ModulesUsage(Inputs);
4474-
if (!ErrOrScanResult) {
4475-
Diags.Report(diag::err_cannot_open_file)
4476-
<< ErrOrScanResult.getError().message();
4477-
return;
4478-
}
4479-
UsesCXXModules = *ErrOrScanResult;
4480-
}
4481-
if (UsesCXXModules)
4482-
BuildDriverManagedModuleBuildActions(C, Args, Inputs, Actions);
4483-
return;
4484-
}
4485-
4486-
BuildDefaultActions(C, Args, Inputs, Actions);
4487-
}
4488-
4489-
void Driver::BuildDefaultActions(Compilation &C, DerivedArgList &Args,
4490-
const InputList &Inputs,
4491-
ActionList &Actions) const {
4492-
44934430
bool UseNewOffloadingDriver =
44944431
C.isOffloadingHostKind(Action::OFK_OpenMP) ||
44954432
C.isOffloadingHostKind(Action::OFK_SYCL) ||
@@ -4773,13 +4710,6 @@ void Driver::BuildDefaultActions(Compilation &C, DerivedArgList &Args,
47734710
Args.ClaimAllArgs(options::OPT_cl_ignored_Group);
47744711
}
47754712

4776-
void Driver::BuildDriverManagedModuleBuildActions(
4777-
Compilation &C, llvm::opt::DerivedArgList &Args, const InputList &Inputs,
4778-
ActionList &Actions) const {
4779-
Diags.Report(diag::remark_performing_driver_managed_module_build);
4780-
return;
4781-
}
4782-
47834713
/// Returns the canonical name for the offloading architecture when using a HIP
47844714
/// or CUDA architecture.
47854715
static StringRef getCanonicalArchString(Compilation &C,

clang/lib/Lex/DependencyDirectivesScanner.cpp

Lines changed: 0 additions & 49 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,50 +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-
if (S.lexModule(First, End))
1113-
return false;
1114-
auto IsCXXNamedModuleDirective = [](const DirectiveWithTokens &D) {
1115-
switch (D.Kind) {
1116-
case dependency_directives_scan::cxx_module_decl:
1117-
case dependency_directives_scan::cxx_import_decl:
1118-
case dependency_directives_scan::cxx_export_module_decl:
1119-
case dependency_directives_scan::cxx_export_import_decl:
1120-
return true;
1121-
default:
1122-
return false;
1123-
}
1124-
};
1125-
return llvm::any_of(S.DirsWithToks, IsCXXNamedModuleDirective);
1126-
}

0 commit comments

Comments
 (0)