diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Frontend/FrontendActions.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Frontend/FrontendActions.cpp | 188 |
1 files changed, 101 insertions, 87 deletions
diff --git a/contrib/llvm/tools/clang/lib/Frontend/FrontendActions.cpp b/contrib/llvm/tools/clang/lib/Frontend/FrontendActions.cpp index 701ef02..40277bd 100644 --- a/contrib/llvm/tools/clang/lib/Frontend/FrontendActions.cpp +++ b/contrib/llvm/tools/clang/lib/Frontend/FrontendActions.cpp @@ -14,6 +14,7 @@ #include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendDiagnostic.h" +#include "clang/Frontend/MultiplexConsumer.h" #include "clang/Frontend/Utils.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/Pragma.h" @@ -79,38 +80,48 @@ std::unique_ptr<ASTConsumer> GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { std::string Sysroot; std::string OutputFile; - raw_ostream *OS = nullptr; - if (ComputeASTConsumerArguments(CI, InFile, Sysroot, OutputFile, OS)) + raw_pwrite_stream *OS = + ComputeASTConsumerArguments(CI, InFile, Sysroot, OutputFile); + if (!OS) return nullptr; if (!CI.getFrontendOpts().RelocatablePCH) Sysroot.clear(); - return llvm::make_unique<PCHGenerator>(CI.getPreprocessor(), OutputFile, - nullptr, Sysroot, OS); + + auto Buffer = std::make_shared<PCHBuffer>(); + std::vector<std::unique_ptr<ASTConsumer>> Consumers; + Consumers.push_back(llvm::make_unique<PCHGenerator>( + CI.getPreprocessor(), OutputFile, nullptr, Sysroot, Buffer)); + Consumers.push_back( + CI.getPCHContainerWriter().CreatePCHContainerGenerator( + CI.getDiagnostics(), CI.getHeaderSearchOpts(), + CI.getPreprocessorOpts(), CI.getTargetOpts(), CI.getLangOpts(), + InFile, OutputFile, OS, Buffer)); + + return llvm::make_unique<MultiplexConsumer>(std::move(Consumers)); } -bool GeneratePCHAction::ComputeASTConsumerArguments(CompilerInstance &CI, - StringRef InFile, - std::string &Sysroot, - std::string &OutputFile, - raw_ostream *&OS) { +raw_pwrite_stream *GeneratePCHAction::ComputeASTConsumerArguments( + CompilerInstance &CI, StringRef InFile, std::string &Sysroot, + std::string &OutputFile) { Sysroot = CI.getHeaderSearchOpts().Sysroot; if (CI.getFrontendOpts().RelocatablePCH && Sysroot.empty()) { CI.getDiagnostics().Report(diag::err_relocatable_without_isysroot); - return true; + return nullptr; } // We use createOutputFile here because this is exposed via libclang, and we // must disable the RemoveFileOnSignal behavior. // We use a temporary to avoid race conditions. - OS = CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true, - /*RemoveFileOnSignal=*/false, InFile, - /*Extension=*/"", /*useTemporary=*/true); + raw_pwrite_stream *OS = + CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true, + /*RemoveFileOnSignal=*/false, InFile, + /*Extension=*/"", /*useTemporary=*/true); if (!OS) - return true; + return nullptr; OutputFile = CI.getFrontendOpts().OutputFile; - return false; + return OS; } std::unique_ptr<ASTConsumer> @@ -118,12 +129,21 @@ GenerateModuleAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { std::string Sysroot; std::string OutputFile; - raw_ostream *OS = nullptr; - if (ComputeASTConsumerArguments(CI, InFile, Sysroot, OutputFile, OS)) + raw_pwrite_stream *OS = + ComputeASTConsumerArguments(CI, InFile, Sysroot, OutputFile); + if (!OS) return nullptr; - return llvm::make_unique<PCHGenerator>(CI.getPreprocessor(), OutputFile, - Module, Sysroot, OS); + auto Buffer = std::make_shared<PCHBuffer>(); + std::vector<std::unique_ptr<ASTConsumer>> Consumers; + Consumers.push_back(llvm::make_unique<PCHGenerator>( + CI.getPreprocessor(), OutputFile, Module, Sysroot, Buffer)); + Consumers.push_back( + CI.getPCHContainerWriter().CreatePCHContainerGenerator( + CI.getDiagnostics(), CI.getHeaderSearchOpts(), + CI.getPreprocessorOpts(), CI.getTargetOpts(), CI.getLangOpts(), + InFile, OutputFile, OS, Buffer)); + return llvm::make_unique<MultiplexConsumer>(std::move(Consumers)); } static SmallVectorImpl<char> & @@ -151,22 +171,6 @@ static std::error_code addHeaderInclude(StringRef HeaderName, return std::error_code(); } -static std::error_code addHeaderInclude(const FileEntry *Header, - SmallVectorImpl<char> &Includes, - const LangOptions &LangOpts, - bool IsExternC) { - // Use an absolute path if we don't have a filename as written in the module - // map file; this ensures that we will identify the right file independent of - // header search paths. - if (llvm::sys::path::is_absolute(Header->getName())) - return addHeaderInclude(Header->getName(), Includes, LangOpts, IsExternC); - - SmallString<256> AbsName(Header->getName()); - if (std::error_code Err = llvm::sys::fs::make_absolute(AbsName)) - return Err; - return addHeaderInclude(AbsName, Includes, LangOpts, IsExternC); -} - /// \brief Collect the set of header includes needed to construct the given /// module and update the TopHeaders file set of the module. /// @@ -195,21 +199,21 @@ collectModuleHeaderIncludes(const LangOptions &LangOpts, FileManager &FileMgr, } // Note that Module->PrivateHeaders will not be a TopHeader. - if (const FileEntry *UmbrellaHeader = Module->getUmbrellaHeader()) { - // FIXME: Track the name as written here. - Module->addTopHeader(UmbrellaHeader); + if (Module::Header UmbrellaHeader = Module->getUmbrellaHeader()) { + Module->addTopHeader(UmbrellaHeader.Entry); if (Module->Parent) { // Include the umbrella header for submodules. - if (std::error_code Err = addHeaderInclude(UmbrellaHeader, Includes, - LangOpts, Module->IsExternC)) + if (std::error_code Err = addHeaderInclude(UmbrellaHeader.NameAsWritten, + Includes, LangOpts, + Module->IsExternC)) return Err; } - } else if (const DirectoryEntry *UmbrellaDir = Module->getUmbrellaDir()) { + } else if (Module::DirectoryName UmbrellaDir = Module->getUmbrellaDir()) { // Add all of the headers we find in this subdirectory. std::error_code EC; SmallString<128> DirNative; - llvm::sys::path::native(UmbrellaDir->getName(), DirNative); - for (llvm::sys::fs::recursive_directory_iterator Dir(DirNative.str(), EC), + llvm::sys::path::native(UmbrellaDir.Entry->getName(), DirNative); + for (llvm::sys::fs::recursive_directory_iterator Dir(DirNative, EC), DirEnd; Dir != DirEnd && !EC; Dir.increment(EC)) { // Check whether this entry has an extension typically associated with @@ -230,11 +234,20 @@ collectModuleHeaderIncludes(const LangOptions &LangOpts, FileManager &FileMgr, if (ModMap.isHeaderUnavailableInModule(Header, Module)) continue; + // Compute the relative path from the directory to this file. + SmallVector<StringRef, 16> Components; + auto PathIt = llvm::sys::path::rbegin(Dir->path()); + for (int I = 0; I != Dir.level() + 1; ++I, ++PathIt) + Components.push_back(*PathIt); + SmallString<128> RelativeHeader(UmbrellaDir.NameAsWritten); + for (auto It = Components.rbegin(), End = Components.rend(); It != End; + ++It) + llvm::sys::path::append(RelativeHeader, *It); + // Include this header as part of the umbrella directory. - // FIXME: Track the name as written through to here. Module->addTopHeader(Header); - if (std::error_code Err = - addHeaderInclude(Header, Includes, LangOpts, Module->IsExternC)) + if (std::error_code Err = addHeaderInclude(RelativeHeader, Includes, + LangOpts, Module->IsExternC)) return Err; } @@ -326,10 +339,9 @@ bool GenerateModuleAction::BeginSourceFileAction(CompilerInstance &CI, // Collect the set of #includes we need to build the module. SmallString<256> HeaderContents; std::error_code Err = std::error_code(); - if (const FileEntry *UmbrellaHeader = Module->getUmbrellaHeader()) - // FIXME: Track the file name as written. - Err = addHeaderInclude(UmbrellaHeader, HeaderContents, CI.getLangOpts(), - Module->IsExternC); + if (Module::Header UmbrellaHeader = Module->getUmbrellaHeader()) + Err = addHeaderInclude(UmbrellaHeader.NameAsWritten, HeaderContents, + CI.getLangOpts(), Module->IsExternC); if (!Err) Err = collectModuleHeaderIncludes( CI.getLangOpts(), FileMgr, @@ -355,11 +367,9 @@ bool GenerateModuleAction::BeginSourceFileAction(CompilerInstance &CI, return true; } -bool GenerateModuleAction::ComputeASTConsumerArguments(CompilerInstance &CI, - StringRef InFile, - std::string &Sysroot, - std::string &OutputFile, - raw_ostream *&OS) { +raw_pwrite_stream *GenerateModuleAction::ComputeASTConsumerArguments( + CompilerInstance &CI, StringRef InFile, std::string &Sysroot, + std::string &OutputFile) { // If no output file was provided, figure out where this module would go // in the module cache. if (CI.getFrontendOpts().OutputFile.empty()) { @@ -368,19 +378,20 @@ bool GenerateModuleAction::ComputeASTConsumerArguments(CompilerInstance &CI, HS.getModuleFileName(CI.getLangOpts().CurrentModule, ModuleMapForUniquing->getName()); } - + // We use createOutputFile here because this is exposed via libclang, and we // must disable the RemoveFileOnSignal behavior. // We use a temporary to avoid race conditions. - OS = CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true, - /*RemoveFileOnSignal=*/false, InFile, - /*Extension=*/"", /*useTemporary=*/true, - /*CreateMissingDirectories=*/true); + raw_pwrite_stream *OS = + CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true, + /*RemoveFileOnSignal=*/false, InFile, + /*Extension=*/"", /*useTemporary=*/true, + /*CreateMissingDirectories=*/true); if (!OS) - return true; - + return nullptr; + OutputFile = CI.getFrontendOpts().OutputFile; - return false; + return OS; } std::unique_ptr<ASTConsumer> @@ -403,13 +414,13 @@ void VerifyPCHAction::ExecuteAction() { CompilerInstance &CI = getCompilerInstance(); bool Preamble = CI.getPreprocessorOpts().PrecompiledPreambleBytes.first != 0; const std::string &Sysroot = CI.getHeaderSearchOpts().Sysroot; - std::unique_ptr<ASTReader> Reader( - new ASTReader(CI.getPreprocessor(), CI.getASTContext(), - Sysroot.empty() ? "" : Sysroot.c_str(), - /*DisableValidation*/ false, - /*AllowPCHWithCompilerErrors*/ false, - /*AllowConfigurationMismatch*/ true, - /*ValidateSystemInputs*/ true)); + std::unique_ptr<ASTReader> Reader(new ASTReader( + CI.getPreprocessor(), CI.getASTContext(), CI.getPCHContainerReader(), + Sysroot.empty() ? "" : Sysroot.c_str(), + /*DisableValidation*/ false, + /*AllowPCHWithCompilerErrors*/ false, + /*AllowConfigurationMismatch*/ true, + /*ValidateSystemInputs*/ true)); Reader->ReadAST(getCurrentFile(), Preamble ? serialization::MK_Preamble @@ -459,11 +470,18 @@ namespace { #define BENIGN_LANGOPT(Name, Bits, Default, Description) #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) #include "clang/Basic/LangOptions.def" + + if (!LangOpts.ModuleFeatures.empty()) { + Out.indent(4) << "Module features:\n"; + for (StringRef Feature : LangOpts.ModuleFeatures) + Out.indent(6) << Feature << "\n"; + } + return false; } - bool ReadTargetOptions(const TargetOptions &TargetOpts, - bool Complain) override { + bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, + bool AllowCompatibleDifferences) override { Out.indent(2) << "Target options:\n"; Out.indent(4) << " Triple: " << TargetOpts.Triple << "\n"; Out.indent(4) << " CPU: " << TargetOpts.CPU << "\n"; @@ -480,9 +498,8 @@ namespace { return false; } - virtual bool - ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, - bool Complain) override { + bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, + bool Complain) override { Out.indent(2) << "Diagnostic options:\n"; #define DIAGOPT(Name, Bits, Default) DUMP_BOOLEAN(DiagOpts->Name, #Name); #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ @@ -501,9 +518,11 @@ namespace { } bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, + StringRef SpecificModuleCachePath, bool Complain) override { Out.indent(2) << "Header search options:\n"; Out.indent(4) << "System root [-isysroot=]: '" << HSOpts.Sysroot << "'\n"; + Out.indent(4) << "Module Cache: '" << SpecificModuleCachePath << "'\n"; DUMP_BOOLEAN(HSOpts.UseBuiltinIncludes, "Use builtin include directories [-nobuiltininc]"); DUMP_BOOLEAN(HSOpts.UseStandardSystemIncludes, @@ -557,9 +576,9 @@ void DumpModuleInfoAction::ExecuteAction() { Out << "Information for module file '" << getCurrentFile() << "':\n"; DumpModuleInfoListener Listener(Out); - ASTReader::readASTFileControlBlock(getCurrentFile(), - getCompilerInstance().getFileManager(), - Listener); + ASTReader::readASTFileControlBlock( + getCurrentFile(), getCompilerInstance().getFileManager(), + getCompilerInstance().getPCHContainerReader(), Listener); } //===----------------------------------------------------------------------===// @@ -598,15 +617,9 @@ void DumpTokensAction::ExecuteAction() { void GeneratePTHAction::ExecuteAction() { CompilerInstance &CI = getCompilerInstance(); - if (CI.getFrontendOpts().OutputFile.empty() || - CI.getFrontendOpts().OutputFile == "-") { - // FIXME: Don't fail this way. - // FIXME: Verify that we can actually seek in the given file. - llvm::report_fatal_error("PTH requires a seekable file for output!"); - } - llvm::raw_fd_ostream *OS = - CI.createDefaultOutputFile(true, getCurrentFile()); - if (!OS) return; + raw_pwrite_stream *OS = CI.createDefaultOutputFile(true, getCurrentFile()); + if (!OS) + return; CacheTokens(CI.getPreprocessor(), OS); } @@ -688,6 +701,7 @@ void PrintPreambleAction::ExecuteAction() { case IK_None: case IK_Asm: case IK_PreprocessedC: + case IK_PreprocessedCuda: case IK_PreprocessedCXX: case IK_PreprocessedObjC: case IK_PreprocessedObjCXX: |