Skip to content

Commit 360752f

Browse files
cor3ntingithub-actions[bot]
authored andcommitted
Automerge: Revert "[clang][modules-driver] Add scanner to detect C++20 module presence" (#147286)
Reverts llvm/llvm-project#145220 This breaks CI when building the documentation ``` Included from /home/runner/work/llvm-project/llvm-project/clang/docs/../include/clang/Basic/Diagnostic.td:74: /home/runner/work/llvm-project/llvm-project/clang/docs/../include/clang/Basic/DiagnosticGroups.td:628:5: error: Diagnostic group contains both remark and non-remark diagnostics def ModulesDriver : DiagGroup<"modules-driver">; ^ ``` https://github.com/llvm/llvm-project/actions/runs/16116118496/job/45470268367
2 parents e78e992 + db389bd commit 360752f

File tree

7 files changed

+1
-453
lines changed

7 files changed

+1
-453
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -577,16 +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-
def warn_modules_driver_unsupported_standard : Warning<
587-
"'-fmodules-driver' is not supported before C++20">,
588-
InGroup<ModulesDriver>;
589-
590580
def warn_drv_delayed_template_parsing_after_cxx20 : Warning<
591581
"-fdelayed-template-parsing is deprecated after C++20">,
592582
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
@@ -625,7 +625,6 @@ def ModuleConflict : DiagGroup<"module-conflict">;
625625
def ModuleFileExtension : DiagGroup<"module-file-extension">;
626626
def ModuleIncludeDirectiveTranslation : DiagGroup<"module-include-translation">;
627627
def ModuleMap : DiagGroup<"module-map">;
628-
def ModulesDriver : DiagGroup<"modules-driver">;
629628
def RoundTripCC1Args : DiagGroup<"round-trip-cc1-args">;
630629
def NewlineEOF : DiagGroup<"newline-eof">;
631630
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-
ScanInputsForCXXModuleUsage(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
@@ -3259,13 +3259,6 @@ def modules_reduced_bmi : Flag<["-"], "fmodules-reduced-bmi">,
32593259
HelpText<"Generate the reduced BMI">,
32603260
MarshallingInfoFlag<FrontendOpts<"GenReducedBMI">>;
32613261

3262-
def fmodules_driver : Flag<["-"], "fmodules-driver">,
3263-
Group<f_Group>, Visibility<[ClangOption]>,
3264-
HelpText<"Enable support for driver managed module builds (experimental)">;
3265-
def fno_modules_driver : Flag<["-"], "fno-modules-driver">,
3266-
Group<f_Group>, Visibility<[ClangOption]>,
3267-
HelpText<"Disable support for driver managed module builds (experimental)">;
3268-
32693262
def experimental_modules_reduced_bmi : Flag<["-"], "fexperimental-modules-reduced-bmi">,
32703263
Group<f_Group>, Visibility<[ClangOption, CC1Option]>, Alias<modules_reduced_bmi>;
32713264

clang/lib/Driver/Driver.cpp

Lines changed: 0 additions & 210 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
#include "ToolChains/WebAssembly.h"
5454
#include "ToolChains/XCore.h"
5555
#include "ToolChains/ZOS.h"
56-
#include "clang/Basic/CharInfo.h"
5756
#include "clang/Basic/DiagnosticDriver.h"
5857
#include "clang/Basic/TargetID.h"
5958
#include "clang/Basic/Version.h"
@@ -4295,13 +4294,6 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
42954294
YcArg = nullptr;
42964295
}
42974296

4298-
if (Args.hasArgNoClaim(options::OPT_fmodules_driver))
4299-
// TODO: Check against all incompatible -fmodules-driver arguments
4300-
if (!ModulesModeCXX20) {
4301-
Diag(diag::warn_modules_driver_unsupported_standard);
4302-
Args.eraseArg(options::OPT_fmodules_driver);
4303-
}
4304-
43054297
Arg *FinalPhaseArg;
43064298
phases::ID FinalPhase = getFinalPhase(Args, &FinalPhaseArg);
43074299

@@ -4428,174 +4420,6 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
44284420
}
44294421
}
44304422

4431-
static void skipWhitespace(const char *&Ptr) {
4432-
while (isWhitespace(*Ptr))
4433-
++Ptr;
4434-
}
4435-
4436-
// Returns the length of EOL, either 0 (no end-of-line), 1 (\n) or 2 (\r\n).
4437-
static unsigned isEOL(const char *Ptr) {
4438-
if (*Ptr == '\0')
4439-
return 0;
4440-
if (*(Ptr + 1) != '\0' && isVerticalWhitespace(Ptr[0]) &&
4441-
isVerticalWhitespace(Ptr[1]) && Ptr[0] != Ptr[1])
4442-
return 2;
4443-
return !!isVerticalWhitespace(Ptr[0]);
4444-
}
4445-
4446-
static void skipLine(const char *&Ptr) {
4447-
for (;;) {
4448-
char LastNonWhitespace = ' ';
4449-
while (!isVerticalWhitespace(*Ptr) && *Ptr != '\0') {
4450-
if (!isHorizontalWhitespace(*Ptr))
4451-
LastNonWhitespace = *Ptr;
4452-
++Ptr;
4453-
}
4454-
4455-
const unsigned Len = isEOL(Ptr);
4456-
if (!Len)
4457-
return;
4458-
4459-
Ptr += Len;
4460-
if (LastNonWhitespace != '\\')
4461-
break;
4462-
}
4463-
}
4464-
4465-
// Returns the length of a line splice sequence (including trailing
4466-
// whitespace), or 0 if no line splice is found.
4467-
static unsigned isLineSplice(const char *Start) {
4468-
if (*Start != '\\')
4469-
return 0;
4470-
4471-
const char *Ptr = Start + 1;
4472-
while (isHorizontalWhitespace(*Ptr))
4473-
++Ptr;
4474-
4475-
if (unsigned Len = isEOL(Ptr))
4476-
return Ptr - Start + Len;
4477-
return 0;
4478-
}
4479-
4480-
static bool trySkipLineSplice(const char *&Ptr) {
4481-
if (unsigned Len = isLineSplice(Ptr); Len) {
4482-
Ptr += Len;
4483-
return true;
4484-
}
4485-
return false;
4486-
}
4487-
4488-
static bool trySkipDirective(const char *&Ptr) {
4489-
if (*Ptr != '#')
4490-
return false;
4491-
4492-
++Ptr;
4493-
skipLine(Ptr);
4494-
return true;
4495-
}
4496-
4497-
static bool trySkipLineComment(const char *&Ptr) {
4498-
if (Ptr[0] != '/' || Ptr[1] != '/')
4499-
return false;
4500-
4501-
Ptr += 2;
4502-
skipLine(Ptr);
4503-
return true;
4504-
}
4505-
4506-
static bool trySkipBlockComment(const char *&Ptr) {
4507-
if (Ptr[0] != '/' || Ptr[1] != '*')
4508-
return false;
4509-
4510-
Ptr += 2;
4511-
while (*Ptr != '\0') {
4512-
if (Ptr[0] == '*' && Ptr[1] == '/') {
4513-
Ptr += 2; // '*/'
4514-
return true;
4515-
}
4516-
++Ptr;
4517-
}
4518-
return true;
4519-
}
4520-
4521-
static bool trySkipComment(const char *&Ptr) {
4522-
return trySkipLineComment(Ptr) || trySkipBlockComment(Ptr);
4523-
}
4524-
4525-
// Skipps over comments and (non-module) directives
4526-
static void skipToRelevantCXXModuleText(const char *&Ptr) {
4527-
while (*Ptr != '\0') {
4528-
skipWhitespace(Ptr);
4529-
if (trySkipComment(Ptr) || trySkipDirective(Ptr) || trySkipLineSplice(Ptr))
4530-
continue;
4531-
break; // Found relevant text!
4532-
}
4533-
}
4534-
4535-
static bool scanBufferForCXXModuleUsage(const llvm::MemoryBuffer &Buffer) {
4536-
const char *Ptr = Buffer.getBufferStart();
4537-
skipToRelevantCXXModuleText(Ptr);
4538-
4539-
// Check if the buffer has enough remaining bytes left for any of the
4540-
// module-related declaration fragments we are checking for, without making
4541-
// the potentially memory-mapped buffer load unnecessary pages.
4542-
constexpr int MinKeywordLength = 6;
4543-
const char *Begin = Ptr;
4544-
for (int i = 0; i < MinKeywordLength; ++i) {
4545-
if (*Ptr == '\0')
4546-
return false;
4547-
++Ptr;
4548-
}
4549-
StringRef Text(Begin, MinKeywordLength);
4550-
4551-
const bool IsGlobalModule = Text.starts_with("module");
4552-
if (!IsGlobalModule && !Text.starts_with("import") &&
4553-
!Text.starts_with("export"))
4554-
return false;
4555-
4556-
// Ensure the keyword has a proper ending and isn't part of a identifier
4557-
// or namespace. For this we might have to skip comments and line
4558-
// continuations.
4559-
while (*Ptr != '\0') {
4560-
if (isWhitespace(*Ptr) || (IsGlobalModule && *Ptr == ';'))
4561-
return true;
4562-
if (trySkipBlockComment(Ptr) || trySkipLineSplice(Ptr))
4563-
continue;
4564-
return false;
4565-
}
4566-
4567-
return false;
4568-
}
4569-
4570-
static bool hasCXXModuleInputType(const Driver::InputList &Inputs) {
4571-
const auto IsTypeCXXModule = [](const auto &Input) -> bool {
4572-
const auto TypeID = Input.first;
4573-
return (TypeID == types::TY_CXXModule);
4574-
};
4575-
return llvm::any_of(Inputs, IsTypeCXXModule);
4576-
}
4577-
4578-
llvm::ErrorOr<bool>
4579-
Driver::ScanInputsForCXXModuleUsage(const InputList &Inputs) const {
4580-
const auto CXXInputs = llvm::make_filter_range(
4581-
Inputs, [](const auto &Input) { return types::isCXX(Input.first); });
4582-
4583-
for (const auto &Input : CXXInputs) {
4584-
StringRef Filename = Input.second->getSpelling();
4585-
auto ErrOrBuffer = VFS->getBufferForFile(Filename);
4586-
if (!ErrOrBuffer)
4587-
return ErrOrBuffer.getError();
4588-
const auto Buffer = std::move(*ErrOrBuffer);
4589-
4590-
if (scanBufferForCXXModuleUsage(*Buffer)) {
4591-
Diags.Report(diag::remark_found_cxx20_module_usage) << Filename;
4592-
return true;
4593-
}
4594-
}
4595-
4596-
return false;
4597-
}
4598-
45994423
void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
46004424
const InputList &Inputs, ActionList &Actions) const {
46014425
llvm::PrettyStackTraceString CrashInfo("Building compilation actions");
@@ -4607,33 +4431,6 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
46074431

46084432
handleArguments(C, Args, Inputs, Actions);
46094433

4610-
if (Args.hasFlag(options::OPT_fmodules_driver,
4611-
options::OPT_fno_modules_driver, false)) {
4612-
// TODO: Move the logic for implicitly enabling explicit-module-builds out
4613-
// of -fmodules-driver once it is no longer experimental.
4614-
// Currently, this serves diagnostic purposes only.
4615-
bool UsesCXXModules = hasCXXModuleInputType(Inputs);
4616-
if (!UsesCXXModules) {
4617-
const auto ErrOrScanResult = ScanInputsForCXXModuleUsage(Inputs);
4618-
if (!ErrOrScanResult) {
4619-
Diags.Report(diag::err_cannot_open_file)
4620-
<< ErrOrScanResult.getError().message();
4621-
return;
4622-
}
4623-
UsesCXXModules = *ErrOrScanResult;
4624-
}
4625-
if (UsesCXXModules)
4626-
BuildDriverManagedModuleBuildActions(C, Args, Inputs, Actions);
4627-
return;
4628-
}
4629-
4630-
BuildDefaultActions(C, Args, Inputs, Actions);
4631-
}
4632-
4633-
void Driver::BuildDefaultActions(Compilation &C, DerivedArgList &Args,
4634-
const InputList &Inputs,
4635-
ActionList &Actions) const {
4636-
46374434
bool UseNewOffloadingDriver =
46384435
C.isOffloadingHostKind(Action::OFK_OpenMP) ||
46394436
C.isOffloadingHostKind(Action::OFK_SYCL) ||
@@ -4917,13 +4714,6 @@ void Driver::BuildDefaultActions(Compilation &C, DerivedArgList &Args,
49174714
Args.ClaimAllArgs(options::OPT_cl_ignored_Group);
49184715
}
49194716

4920-
void Driver::BuildDriverManagedModuleBuildActions(
4921-
Compilation &C, llvm::opt::DerivedArgList &Args, const InputList &Inputs,
4922-
ActionList &Actions) const {
4923-
Diags.Report(diag::remark_performing_driver_managed_module_build);
4924-
return;
4925-
}
4926-
49274717
/// Returns the canonical name for the offloading architecture when using a HIP
49284718
/// or CUDA architecture.
49294719
static StringRef getCanonicalArchString(Compilation &C,

0 commit comments

Comments
 (0)