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-
45994423void 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.
49294719static StringRef getCanonicalArchString (Compilation &C,
0 commit comments