diff options
Diffstat (limited to 'lib/Frontend/PrecompiledPreamble.cpp')
-rw-r--r-- | lib/Frontend/PrecompiledPreamble.cpp | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/lib/Frontend/PrecompiledPreamble.cpp b/lib/Frontend/PrecompiledPreamble.cpp index 7e1323fd83bb9..30ae2db26d862 100644 --- a/lib/Frontend/PrecompiledPreamble.cpp +++ b/lib/Frontend/PrecompiledPreamble.cpp @@ -40,7 +40,7 @@ namespace { StringRef getInMemoryPreamblePath() { #if defined(LLVM_ON_UNIX) return "/__clang_tmp/___clang_inmemory_preamble___"; -#elif defined(LLVM_ON_WIN32) +#elif defined(_WIN32) return "C:\\__clang_tmp\\___clang_inmemory_preamble___"; #else #warning "Unknown platform. Defaulting to UNIX-style paths for in-memory PCHs" @@ -63,6 +63,16 @@ createVFSOverlayForPreamblePCH(StringRef PCHFilename, return Overlay; } +class PreambleDependencyCollector : public DependencyCollector { +public: + // We want to collect all dependencies for correctness. Avoiding the real + // system dependencies (e.g. stl from /usr/lib) would probably be a good idea, + // but there is no way to distinguish between those and the ones that can be + // spuriously added by '-isystem' (e.g. to suppress warnings from those + // headers). + bool needSystemDependencies() override { return true; } +}; + /// Keeps a track of files to be deleted in destructor. class TemporaryFiles { public: @@ -303,8 +313,6 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build( VFS = createVFSFromCompilerInvocation(Clang->getInvocation(), Diagnostics, VFS); - if (!VFS) - return BuildPreambleError::CouldntCreateVFSOverlay; // Create a file manager object to provide access to and cache the filesystem. Clang->setFileManager(new FileManager(Clang->getFileSystemOpts(), VFS)); @@ -313,7 +321,7 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build( Clang->setSourceManager( new SourceManager(Diagnostics, Clang->getFileManager())); - auto PreambleDepCollector = std::make_shared<DependencyCollector>(); + auto PreambleDepCollector = std::make_shared<PreambleDependencyCollector>(); Clang->addDependencyCollector(PreambleDepCollector); // Remap the main source file to the preamble buffer. @@ -485,20 +493,15 @@ bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation, void PrecompiledPreamble::AddImplicitPreamble( CompilerInvocation &CI, IntrusiveRefCntPtr<vfs::FileSystem> &VFS, llvm::MemoryBuffer *MainFileBuffer) const { - assert(VFS && "VFS must not be null"); - - auto &PreprocessorOpts = CI.getPreprocessorOpts(); - - // Remap main file to point to MainFileBuffer. - auto MainFilePath = CI.getFrontendOpts().Inputs[0].getFile(); - PreprocessorOpts.addRemappedFile(MainFilePath, MainFileBuffer); - - // Configure ImpicitPCHInclude. - PreprocessorOpts.PrecompiledPreambleBytes.first = PreambleBytes.size(); - PreprocessorOpts.PrecompiledPreambleBytes.second = PreambleEndsAtStartOfLine; - PreprocessorOpts.DisablePCHValidation = true; + PreambleBounds Bounds(PreambleBytes.size(), PreambleEndsAtStartOfLine); + configurePreamble(Bounds, CI, VFS, MainFileBuffer); +} - setupPreambleStorage(Storage, PreprocessorOpts, VFS); +void PrecompiledPreamble::OverridePreamble( + CompilerInvocation &CI, IntrusiveRefCntPtr<vfs::FileSystem> &VFS, + llvm::MemoryBuffer *MainFileBuffer) const { + auto Bounds = ComputePreambleBounds(*CI.getLangOpts(), MainFileBuffer, 0); + configurePreamble(Bounds, CI, VFS, MainFileBuffer); } PrecompiledPreamble::PrecompiledPreamble( @@ -681,6 +684,27 @@ PrecompiledPreamble::PreambleFileHash::createForMemoryBuffer( return Result; } +void PrecompiledPreamble::configurePreamble( + PreambleBounds Bounds, CompilerInvocation &CI, + IntrusiveRefCntPtr<vfs::FileSystem> &VFS, + llvm::MemoryBuffer *MainFileBuffer) const { + assert(VFS); + + auto &PreprocessorOpts = CI.getPreprocessorOpts(); + + // Remap main file to point to MainFileBuffer. + auto MainFilePath = CI.getFrontendOpts().Inputs[0].getFile(); + PreprocessorOpts.addRemappedFile(MainFilePath, MainFileBuffer); + + // Configure ImpicitPCHInclude. + PreprocessorOpts.PrecompiledPreambleBytes.first = Bounds.Size; + PreprocessorOpts.PrecompiledPreambleBytes.second = + Bounds.PreambleEndsAtStartOfLine; + PreprocessorOpts.DisablePCHValidation = true; + + setupPreambleStorage(Storage, PreprocessorOpts, VFS); +} + void PrecompiledPreamble::setupPreambleStorage( const PCHStorage &Storage, PreprocessorOptions &PreprocessorOpts, IntrusiveRefCntPtr<vfs::FileSystem> &VFS) { @@ -740,8 +764,6 @@ std::string BuildPreambleErrorCategory::message(int condition) const { return "Could not create temporary file for PCH"; case BuildPreambleError::CouldntCreateTargetInfo: return "CreateTargetInfo() return null"; - case BuildPreambleError::CouldntCreateVFSOverlay: - return "Could not create VFS Overlay"; case BuildPreambleError::BeginSourceFileFailed: return "BeginSourceFile() return an error"; case BuildPreambleError::CouldntEmitPCH: |