diff options
Diffstat (limited to 'clang/lib/Frontend/FrontendAction.cpp')
-rw-r--r-- | clang/lib/Frontend/FrontendAction.cpp | 81 |
1 files changed, 49 insertions, 32 deletions
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index 934d17b3c925..59a968b5c709 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -157,10 +157,9 @@ FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, bool FoundAllPlugins = true; for (const std::string &Arg : CI.getFrontendOpts().AddPluginActions) { bool Found = false; - for (FrontendPluginRegistry::iterator it = FrontendPluginRegistry::begin(), - ie = FrontendPluginRegistry::end(); - it != ie; ++it) { - if (it->getName() == Arg) + for (const FrontendPluginRegistry::entry &Plugin : + FrontendPluginRegistry::entries()) { + if (Plugin.getName() == Arg) Found = true; } if (!Found) { @@ -183,25 +182,24 @@ FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, // or after it (in AfterConsumers) std::vector<std::unique_ptr<ASTConsumer>> Consumers; std::vector<std::unique_ptr<ASTConsumer>> AfterConsumers; - for (FrontendPluginRegistry::iterator it = FrontendPluginRegistry::begin(), - ie = FrontendPluginRegistry::end(); - it != ie; ++it) { - std::unique_ptr<PluginASTAction> P = it->instantiate(); + for (const FrontendPluginRegistry::entry &Plugin : + FrontendPluginRegistry::entries()) { + std::unique_ptr<PluginASTAction> P = Plugin.instantiate(); PluginASTAction::ActionType ActionType = P->getActionType(); if (ActionType == PluginASTAction::Cmdline) { // This is O(|plugins| * |add_plugins|), but since both numbers are // way below 50 in practice, that's ok. - for (size_t i = 0, e = CI.getFrontendOpts().AddPluginActions.size(); - i != e; ++i) { - if (it->getName() == CI.getFrontendOpts().AddPluginActions[i]) { - ActionType = PluginASTAction::AddAfterMainAction; - break; - } - } + if (llvm::any_of(CI.getFrontendOpts().AddPluginActions, + [&](const std::string &PluginAction) { + return PluginAction == Plugin.getName(); + })) + ActionType = PluginASTAction::AddAfterMainAction; } if ((ActionType == PluginASTAction::AddBeforeMainAction || ActionType == PluginASTAction::AddAfterMainAction) && - P->ParseArgs(CI, CI.getFrontendOpts().PluginArgs[it->getName()])) { + P->ParseArgs( + CI, + CI.getFrontendOpts().PluginArgs[std::string(Plugin.getName())])) { std::unique_ptr<ASTConsumer> PluginConsumer = P->CreateASTConsumer(CI, InFile); if (ActionType == PluginASTAction::AddBeforeMainAction) { Consumers.push_back(std::move(PluginConsumer)); @@ -363,6 +361,7 @@ static std::error_code collectModuleHeaderIncludes( llvm::sys::path::native(UmbrellaDir.Entry->getName(), DirNative); llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem(); + SmallVector<std::pair<std::string, const FileEntry *>, 8> Headers; for (llvm::vfs::recursive_directory_iterator Dir(FS, DirNative, EC), End; Dir != End && !EC; Dir.increment(EC)) { // Check whether this entry has an extension typically associated with @@ -393,13 +392,25 @@ static std::error_code collectModuleHeaderIncludes( ++It) llvm::sys::path::append(RelativeHeader, *It); - // Include this header as part of the umbrella directory. - Module->addTopHeader(*Header); - addHeaderInclude(RelativeHeader, Includes, LangOpts, Module->IsExternC); + std::string RelName = RelativeHeader.c_str(); + Headers.push_back(std::make_pair(RelName, *Header)); } if (EC) return EC; + + // Sort header paths and make the header inclusion order deterministic + // across different OSs and filesystems. + llvm::sort(Headers.begin(), Headers.end(), []( + const std::pair<std::string, const FileEntry *> &LHS, + const std::pair<std::string, const FileEntry *> &RHS) { + return LHS.first < RHS.first; + }); + for (auto &H : Headers) { + // Include this header as part of the umbrella directory. + Module->addTopHeader(H.second); + addHeaderInclude(H.first, Includes, LangOpts, Module->IsExternC); + } } // Recurse into submodules. @@ -564,8 +575,9 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, StringRef InputFile = Input.getFile(); std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile( - InputFile, CI.getPCHContainerReader(), ASTUnit::LoadPreprocessorOnly, - ASTDiags, CI.getFileSystemOpts(), CI.getCodeGenOpts().DebugTypeExtRefs); + std::string(InputFile), CI.getPCHContainerReader(), + ASTUnit::LoadPreprocessorOnly, ASTDiags, CI.getFileSystemOpts(), + CI.getCodeGenOpts().DebugTypeExtRefs); if (!AST) goto failure; @@ -592,10 +604,11 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, if (&MF != &PrimaryModule) CI.getFrontendOpts().ModuleFiles.push_back(MF.FileName); - ASTReader->visitTopLevelModuleMaps(PrimaryModule, - [&](const FileEntry *FE) { - CI.getFrontendOpts().ModuleMapFiles.push_back(FE->getName()); - }); + ASTReader->visitTopLevelModuleMaps( + PrimaryModule, [&](const FileEntry *FE) { + CI.getFrontendOpts().ModuleMapFiles.push_back( + std::string(FE->getName())); + }); } // Set up the input file for replay purposes. @@ -630,8 +643,9 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, StringRef InputFile = Input.getFile(); std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile( - InputFile, CI.getPCHContainerReader(), ASTUnit::LoadEverything, Diags, - CI.getFileSystemOpts(), CI.getCodeGenOpts().DebugTypeExtRefs); + std::string(InputFile), CI.getPCHContainerReader(), + ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts(), + CI.getCodeGenOpts().DebugTypeExtRefs); if (!AST) goto failure; @@ -725,7 +739,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, Dir->path(), FileMgr, CI.getPCHContainerReader(), CI.getLangOpts(), CI.getTargetOpts(), CI.getPreprocessorOpts(), SpecificModuleCachePath)) { - PPOpts.ImplicitPCHInclude = Dir->path(); + PPOpts.ImplicitPCHInclude = std::string(Dir->path()); Found = true; break; } @@ -783,7 +797,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, auto Kind = CurrentModule->IsSystem ? SrcMgr::C_System : SrcMgr::C_User; auto &SourceMgr = CI.getSourceManager(); auto BufferID = SourceMgr.createFileID(std::move(Buffer), Kind); - assert(BufferID.isValid() && "couldn't creaate module buffer ID"); + assert(BufferID.isValid() && "couldn't create module buffer ID"); SourceMgr.setMainFileID(BufferID); } } @@ -817,7 +831,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, // For preprocessed files, check if the first line specifies the original // source file name with a linemarker. - std::string PresumedInputFile = getCurrentFileOrBufferName(); + std::string PresumedInputFile = std::string(getCurrentFileOrBufferName()); if (Input.isPreprocessed()) ReadOriginalFileName(CI, PresumedInputFile); @@ -836,7 +850,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, source = createChainedIncludesSource(CI, FinalReader); if (!source) goto failure; - CI.setModuleManager(static_cast<ASTReader *>(FinalReader.get())); + CI.setASTReader(static_cast<ASTReader *>(FinalReader.get())); CI.getASTContext().setExternalSource(source); } else if (CI.getLangOpts().Modules || !CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) { @@ -866,7 +880,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, if (!CI.getASTContext().getExternalSource()) goto failure; } - // If modules are enabled, create the module manager before creating + // If modules are enabled, create the AST reader before creating // any builtins, so that all declarations know that they might be // extended by an external source. if (CI.getLangOpts().Modules || !CI.hasASTContext() || @@ -1077,6 +1091,9 @@ void WrapperFrontendAction::ExecuteAction() { void WrapperFrontendAction::EndSourceFileAction() { WrappedAction->EndSourceFileAction(); } +bool WrapperFrontendAction::shouldEraseOutputFiles() { + return WrappedAction->shouldEraseOutputFiles(); +} bool WrapperFrontendAction::usesPreprocessorOnly() const { return WrappedAction->usesPreprocessorOnly(); |