12 changes: 6 additions & 6 deletions clang/include/clang/Tooling/Tooling.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ inline std::unique_ptr<FrontendActionFactory> newFrontendActionFactory(
bool runToolOnCode(clang::FrontendAction *ToolAction, const Twine &Code,
const Twine &FileName = "input.cc",
std::shared_ptr<PCHContainerOperations> PCHContainerOps =
std::make_shared<RawPCHContainerOperations>());
std::make_shared<PCHContainerOperations>());

/// The first part of the pair is the filename, the second part the
/// file-content.
Expand All @@ -171,7 +171,7 @@ bool runToolOnCodeWithArgs(
clang::FrontendAction *ToolAction, const Twine &Code,
const std::vector<std::string> &Args, const Twine &FileName = "input.cc",
std::shared_ptr<PCHContainerOperations> PCHContainerOps =
std::make_shared<RawPCHContainerOperations>(),
std::make_shared<PCHContainerOperations>(),
const FileContentMappings &VirtualMappedFiles = FileContentMappings());

/// \brief Builds an AST for 'Code'.
Expand All @@ -185,7 +185,7 @@ bool runToolOnCodeWithArgs(
std::unique_ptr<ASTUnit>
buildASTFromCode(const Twine &Code, const Twine &FileName = "input.cc",
std::shared_ptr<PCHContainerOperations> PCHContainerOps =
std::make_shared<RawPCHContainerOperations>());
std::make_shared<PCHContainerOperations>());

/// \brief Builds an AST for 'Code' with additional flags.
///
Expand All @@ -200,7 +200,7 @@ std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs(
const Twine &Code, const std::vector<std::string> &Args,
const Twine &FileName = "input.cc",
std::shared_ptr<PCHContainerOperations> PCHContainerOps =
std::make_shared<RawPCHContainerOperations>());
std::make_shared<PCHContainerOperations>());

/// \brief Utility to run a FrontendAction in a single clang invocation.
class ToolInvocation {
Expand All @@ -219,7 +219,7 @@ class ToolInvocation {
ToolInvocation(std::vector<std::string> CommandLine, FrontendAction *FAction,
FileManager *Files,
std::shared_ptr<PCHContainerOperations> PCHContainerOps =
std::make_shared<RawPCHContainerOperations>());
std::make_shared<PCHContainerOperations>());

/// \brief Create a tool invocation.
///
Expand Down Expand Up @@ -288,7 +288,7 @@ class ClangTool {
ClangTool(const CompilationDatabase &Compilations,
ArrayRef<std::string> SourcePaths,
std::shared_ptr<PCHContainerOperations> PCHContainerOps =
std::make_shared<RawPCHContainerOperations>());
std::make_shared<PCHContainerOperations>());

~ClangTool();

Expand Down
10 changes: 6 additions & 4 deletions clang/lib/ARCMigrate/ARCMT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static bool HasARCRuntime(CompilerInvocation &origCI) {

static CompilerInvocation *
createInvocationForMigration(CompilerInvocation &origCI,
const PCHContainerOperations &PCHContainerOps) {
const PCHContainerReader &PCHContainerRdr) {
std::unique_ptr<CompilerInvocation> CInvok;
CInvok.reset(new CompilerInvocation(origCI));
PreprocessorOptions &PPOpts = CInvok->getPreprocessorOpts();
Expand All @@ -180,7 +180,7 @@ createInvocationForMigration(CompilerInvocation &origCI,
new DiagnosticsEngine(DiagID, &origCI.getDiagnosticOpts(),
new IgnoringDiagConsumer()));
std::string OriginalFile = ASTReader::getOriginalSourceFile(
PPOpts.ImplicitPCHInclude, FileMgr, PCHContainerOps, *Diags);
PPOpts.ImplicitPCHInclude, FileMgr, PCHContainerRdr, *Diags);
if (!OriginalFile.empty())
PPOpts.Includes.insert(PPOpts.Includes.begin(), OriginalFile);
PPOpts.ImplicitPCHInclude.clear();
Expand Down Expand Up @@ -247,7 +247,8 @@ bool arcmt::checkForManualIssues(
assert(!transforms.empty());

std::unique_ptr<CompilerInvocation> CInvok;
CInvok.reset(createInvocationForMigration(origCI, *PCHContainerOps));
CInvok.reset(
createInvocationForMigration(origCI, PCHContainerOps->getRawReader()));
CInvok->getFrontendOpts().Inputs.clear();
CInvok->getFrontendOpts().Inputs.push_back(Input);

Expand Down Expand Up @@ -517,7 +518,8 @@ MigrationProcess::MigrationProcess(
bool MigrationProcess::applyTransform(TransformFn trans,
RewriteListener *listener) {
std::unique_ptr<CompilerInvocation> CInvok;
CInvok.reset(createInvocationForMigration(OrigCI, *PCHContainerOps));
CInvok.reset(
createInvocationForMigration(OrigCI, PCHContainerOps->getRawReader()));
CInvok->getDiagnosticOpts().IgnoreWarnings = true;

Remapper.applyMappings(CInvok->getPreprocessorOpts());
Expand Down
4 changes: 3 additions & 1 deletion clang/lib/Basic/FileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,4 +587,6 @@ void FileManager::PrintStats() const {
//llvm::errs() << PagesMapped << BytesOfPagesMapped << FSLookups;
}

PCHContainerOperations::~PCHContainerOperations() {}
// Virtual destructors for abstract base classes that need live in Basic.
PCHContainerWriter::~PCHContainerWriter() {}
PCHContainerReader::~PCHContainerReader() {}
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class PCHContainerGenerator : public ASTConsumer {
} // namespace

std::unique_ptr<ASTConsumer>
ObjectFilePCHContainerOperations::CreatePCHContainerGenerator(
ObjectFilePCHContainerWriter::CreatePCHContainerGenerator(
DiagnosticsEngine &Diags, const HeaderSearchOptions &HSO,
const PreprocessorOptions &PPO, const TargetOptions &TO,
const LangOptions &LO, const std::string &MainFileName,
Expand All @@ -166,7 +166,7 @@ ObjectFilePCHContainerOperations::CreatePCHContainerGenerator(
Diags, HSO, PPO, TO, LO, MainFileName, OutputFileName, OS, Buffer);
}

void ObjectFilePCHContainerOperations::ExtractPCH(
void ObjectFilePCHContainerReader::ExtractPCH(
llvm::MemoryBufferRef Buffer, llvm::BitstreamReader &StreamFile) const {
if (auto OF = llvm::object::ObjectFile::createObjectFile(Buffer)) {
auto *Obj = OF.get().get();
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Frontend/ASTMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void ASTMergeAction::ExecuteAction() {
*CI.getDiagnostics().getClient()),
/*ShouldOwnClient=*/true));
std::unique_ptr<ASTUnit> Unit =
ASTUnit::LoadFromASTFile(ASTFiles[I], CI.getPCHContainerOperations(),
ASTUnit::LoadFromASTFile(ASTFiles[I], CI.getPCHContainerReader(),
Diags, CI.getFileSystemOpts(), false);

if (!Unit)
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Frontend/ASTUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ void ASTUnit::ConfigureDiags(IntrusiveRefCntPtr<DiagnosticsEngine> Diags,

std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
const std::string &Filename,
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
const PCHContainerReader &PCHContainerRdr,
IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
const FileSystemOptions &FileSystemOpts, bool OnlyLocalDecls,
ArrayRef<RemappedFile> RemappedFiles, bool CaptureDiagnostics,
Expand All @@ -676,7 +676,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
AST->getFileManager(),
UserFilesAreVolatile);
AST->HSOpts = new HeaderSearchOptions();

AST->HSOpts->ModuleFormat = PCHContainerRdr.getFormat();
AST->HeaderInfo.reset(new HeaderSearch(AST->HSOpts,
AST->getSourceManager(),
AST->getDiagnostics(),
Expand Down Expand Up @@ -708,7 +708,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
bool disableValid = false;
if (::getenv("LIBCLANG_DISABLE_PCH_VALIDATION"))
disableValid = true;
AST->Reader = new ASTReader(PP, Context, *PCHContainerOps,
AST->Reader = new ASTReader(PP, Context, PCHContainerRdr,
/*isysroot=*/"",
/*DisableValidation=*/disableValid,
AllowPCHWithCompilerErrors);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Frontend/ChainedIncludesSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ createASTReader(CompilerInstance &CI, StringRef pchFile,
Preprocessor &PP = CI.getPreprocessor();
std::unique_ptr<ASTReader> Reader;
Reader.reset(new ASTReader(PP, CI.getASTContext(),
*CI.getPCHContainerOperations(),
CI.getPCHContainerReader(),
/*isysroot=*/"", /*DisableValidation=*/true));
for (unsigned ti = 0; ti < bufNames.size(); ++ti) {
StringRef sr(bufNames[ti]);
Expand Down
16 changes: 8 additions & 8 deletions clang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
PP->getFileManager(), PPOpts);

// Predefine macros and configure the preprocessor.
InitializePreprocessor(*PP, PPOpts, *getPCHContainerOperations(),
InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(),
getFrontendOpts());

// Initialize the header search object.
Expand Down Expand Up @@ -399,21 +399,21 @@ void CompilerInstance::createPCHExternalASTSource(
ModuleManager = createPCHExternalASTSource(
Path, getHeaderSearchOpts().Sysroot, DisablePCHValidation,
AllowPCHWithCompilerErrors, getPreprocessor(), getASTContext(),
*getPCHContainerOperations(), DeserializationListener,
getPCHContainerReader(), DeserializationListener,
OwnDeserializationListener, Preamble,
getFrontendOpts().UseGlobalModuleIndex);
}

IntrusiveRefCntPtr<ASTReader> CompilerInstance::createPCHExternalASTSource(
StringRef Path, StringRef Sysroot, bool DisablePCHValidation,
bool AllowPCHWithCompilerErrors, Preprocessor &PP, ASTContext &Context,
const PCHContainerOperations &PCHContainerOps,
const PCHContainerReader &PCHContainerRdr,
void *DeserializationListener, bool OwnDeserializationListener,
bool Preamble, bool UseGlobalModuleIndex) {
HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts();

IntrusiveRefCntPtr<ASTReader> Reader(new ASTReader(
PP, Context, PCHContainerOps, Sysroot.empty() ? "" : Sysroot.data(),
PP, Context, PCHContainerRdr, Sysroot.empty() ? "" : Sysroot.data(),
DisablePCHValidation, AllowPCHWithCompilerErrors,
/*AllowConfigurationMismatch*/ false, HSOpts.ModulesValidateSystemHeaders,
UseGlobalModuleIndex));
Expand Down Expand Up @@ -1244,7 +1244,7 @@ void CompilerInstance::createModuleManager() {
ReadTimer = llvm::make_unique<llvm::Timer>("Reading modules",
*FrontendTimerGroup);
ModuleManager = new ASTReader(
getPreprocessor(), *Context, *getPCHContainerOperations(),
getPreprocessor(), *Context, getPCHContainerReader(),
Sysroot.empty() ? "" : Sysroot.c_str(), PPOpts.DisablePCHValidation,
/*AllowASTWithCompilerErrors=*/false,
/*AllowConfigurationMismatch=*/false,
Expand Down Expand Up @@ -1296,7 +1296,7 @@ bool CompilerInstance::loadModuleFile(StringRef FileName) {
ModuleFileStack.push_back(FileName);
ModuleNameStack.push_back(StringRef());
if (ASTReader::readASTFileControlBlock(FileName, CI.getFileManager(),
*CI.getPCHContainerOperations(),
CI.getPCHContainerReader(),
*this)) {
CI.getDiagnostics().Report(
SourceLocation(), CI.getFileManager().getBufferForFile(FileName)
Expand Down Expand Up @@ -1667,7 +1667,7 @@ GlobalModuleIndex *CompilerInstance::loadGlobalModuleIndex(
llvm::sys::fs::create_directories(
getPreprocessor().getHeaderSearchInfo().getModuleCachePath());
GlobalModuleIndex::writeIndex(
getFileManager(), *getPCHContainerOperations(),
getFileManager(), getPCHContainerReader(),
getPreprocessor().getHeaderSearchInfo().getModuleCachePath());
ModuleManager->resetForReload();
ModuleManager->loadGlobalIndex();
Expand Down Expand Up @@ -1695,7 +1695,7 @@ GlobalModuleIndex *CompilerInstance::loadGlobalModuleIndex(
}
if (RecreateIndex) {
GlobalModuleIndex::writeIndex(
getFileManager(), *getPCHContainerOperations(),
getFileManager(), getPCHContainerReader(),
getPreprocessor().getHeaderSearchInfo().getModuleCachePath());
ModuleManager->resetForReload();
ModuleManager->loadGlobalIndex();
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,8 @@ static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) {
getLastArgUInt64Value(Args, OPT_fbuild_session_timestamp, 0);
Opts.ModulesValidateSystemHeaders =
Args.hasArg(OPT_fmodules_validate_system_headers);
if (const Arg *A = Args.getLastArg(OPT_fmodule_format_EQ))
Opts.ModuleFormat = A->getValue();

for (const Arg *A : Args.filtered(OPT_fmodules_ignore_macro)) {
StringRef MacroDef = A->getValue();
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Frontend/FrontendAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(&CI.getDiagnostics());

std::unique_ptr<ASTUnit> AST =
ASTUnit::LoadFromASTFile(InputFile, CI.getPCHContainerOperations(),
ASTUnit::LoadFromASTFile(InputFile, CI.getPCHContainerReader(),
Diags, CI.getFileSystemOpts());

if (!AST)
Expand Down Expand Up @@ -273,7 +273,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
Dir != DirEnd && !EC; Dir.increment(EC)) {
// Check whether this is an acceptable AST file.
if (ASTReader::isAcceptableASTFile(
Dir->path(), FileMgr, *CI.getPCHContainerOperations(),
Dir->path(), FileMgr, CI.getPCHContainerReader(),
CI.getLangOpts(), CI.getTargetOpts(), CI.getPreprocessorOpts(),
SpecificModuleCachePath)) {
PPOpts.ImplicitPCHInclude = Dir->path();
Expand Down Expand Up @@ -443,7 +443,7 @@ bool FrontendAction::Execute() {
if (CI.shouldBuildGlobalModuleIndex() && CI.hasFileManager() &&
CI.hasPreprocessor()) {
GlobalModuleIndex::writeIndex(
CI.getFileManager(), *CI.getPCHContainerOperations(),
CI.getFileManager(), CI.getPCHContainerReader(),
CI.getPreprocessor().getHeaderSearchInfo().getModuleCachePath());
}

Expand Down
8 changes: 4 additions & 4 deletions clang/lib/Frontend/FrontendActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
Consumers.push_back(llvm::make_unique<PCHGenerator>(
CI.getPreprocessor(), OutputFile, nullptr, Sysroot, Buffer));
Consumers.push_back(
CI.getPCHContainerOperations()->CreatePCHContainerGenerator(
CI.getPCHContainerWriter().CreatePCHContainerGenerator(
CI.getDiagnostics(), CI.getHeaderSearchOpts(),
CI.getPreprocessorOpts(), CI.getTargetOpts(), CI.getLangOpts(),
InFile, OutputFile, OS, Buffer));
Expand Down Expand Up @@ -139,7 +139,7 @@ GenerateModuleAction::CreateASTConsumer(CompilerInstance &CI,
Consumers.push_back(llvm::make_unique<PCHGenerator>(
CI.getPreprocessor(), OutputFile, Module, Sysroot, Buffer));
Consumers.push_back(
CI.getPCHContainerOperations()->CreatePCHContainerGenerator(
CI.getPCHContainerWriter().CreatePCHContainerGenerator(
CI.getDiagnostics(), CI.getHeaderSearchOpts(),
CI.getPreprocessorOpts(), CI.getTargetOpts(), CI.getLangOpts(),
InFile, OutputFile, OS, Buffer));
Expand Down Expand Up @@ -415,7 +415,7 @@ void VerifyPCHAction::ExecuteAction() {
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(), *CI.getPCHContainerOperations(),
CI.getPreprocessor(), CI.getASTContext(), CI.getPCHContainerReader(),
Sysroot.empty() ? "" : Sysroot.c_str(),
/*DisableValidation*/ false,
/*AllowPCHWithCompilerErrors*/ false,
Expand Down Expand Up @@ -578,7 +578,7 @@ void DumpModuleInfoAction::ExecuteAction() {
DumpModuleInfoListener Listener(Out);
ASTReader::readASTFileControlBlock(
getCurrentFile(), getCompilerInstance().getFileManager(),
*getCompilerInstance().getPCHContainerOperations(), Listener);
getCompilerInstance().getPCHContainerReader(), Listener);
}

//===----------------------------------------------------------------------===//
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/Frontend/InitPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ static void AddImplicitIncludePTH(MacroBuilder &Builder, Preprocessor &PP,
/// \brief Add an implicit \#include using the original file used to generate
/// a PCH file.
static void AddImplicitIncludePCH(MacroBuilder &Builder, Preprocessor &PP,
const PCHContainerOperations &PCHContainerOps,
const PCHContainerReader &PCHContainerRdr,
StringRef ImplicitIncludePCH) {
std::string OriginalFile =
ASTReader::getOriginalSourceFile(ImplicitIncludePCH, PP.getFileManager(),
PCHContainerOps, PP.getDiagnostics());
PCHContainerRdr, PP.getDiagnostics());
if (OriginalFile.empty())
return;

Expand Down Expand Up @@ -902,7 +902,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
///
void clang::InitializePreprocessor(
Preprocessor &PP, const PreprocessorOptions &InitOpts,
const PCHContainerOperations &PCHContainerOps,
const PCHContainerReader &PCHContainerRdr,
const FrontendOptions &FEOpts) {
const LangOptions &LangOpts = PP.getLangOpts();
std::string PredefineBuffer;
Expand Down Expand Up @@ -962,7 +962,7 @@ void clang::InitializePreprocessor(

// Process -include-pch/-include-pth directives.
if (!InitOpts.ImplicitPCHInclude.empty())
AddImplicitIncludePCH(Builder, PP, PCHContainerOps,
AddImplicitIncludePCH(Builder, PP, PCHContainerRdr,
InitOpts.ImplicitPCHInclude);
if (!InitOpts.ImplicitPTHInclude.empty())
AddImplicitIncludePTH(Builder, PP, InitOpts.ImplicitPTHInclude);
Expand Down
31 changes: 18 additions & 13 deletions clang/lib/Frontend/PCHContainerOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@ using namespace clang;
namespace {

/// \brief A PCHContainerGenerator that writes out the PCH to a flat file.
class PCHContainerGenerator : public ASTConsumer {
class RawPCHContainerGenerator : public ASTConsumer {
std::shared_ptr<PCHBuffer> Buffer;
raw_pwrite_stream *OS;

public:
PCHContainerGenerator(DiagnosticsEngine &Diags,
const HeaderSearchOptions &HSO,
const PreprocessorOptions &PPO, const TargetOptions &TO,
const LangOptions &LO, const std::string &MainFileName,
const std::string &OutputFileName,
llvm::raw_pwrite_stream *OS,
std::shared_ptr<PCHBuffer> Buffer)
RawPCHContainerGenerator(DiagnosticsEngine &Diags,
const HeaderSearchOptions &HSO,
const PreprocessorOptions &PPO,
const TargetOptions &TO, const LangOptions &LO,
const std::string &MainFileName,
const std::string &OutputFileName,
llvm::raw_pwrite_stream *OS,
std::shared_ptr<PCHBuffer> Buffer)
: Buffer(Buffer), OS(OS) {}

virtual ~PCHContainerGenerator() {}
virtual ~RawPCHContainerGenerator() {}

void HandleTranslationUnit(ASTContext &Ctx) override {
if (Buffer->IsComplete) {
Expand All @@ -50,19 +51,23 @@ class PCHContainerGenerator : public ASTConsumer {
};
}

std::unique_ptr<ASTConsumer>
RawPCHContainerOperations::CreatePCHContainerGenerator(
std::unique_ptr<ASTConsumer> RawPCHContainerWriter::CreatePCHContainerGenerator(
DiagnosticsEngine &Diags, const HeaderSearchOptions &HSO,
const PreprocessorOptions &PPO, const TargetOptions &TO,
const LangOptions &LO, const std::string &MainFileName,
const std::string &OutputFileName, llvm::raw_pwrite_stream *OS,
std::shared_ptr<PCHBuffer> Buffer) const {
return llvm::make_unique<PCHContainerGenerator>(
return llvm::make_unique<RawPCHContainerGenerator>(
Diags, HSO, PPO, TO, LO, MainFileName, OutputFileName, OS, Buffer);
}

void RawPCHContainerOperations::ExtractPCH(
void RawPCHContainerReader::ExtractPCH(
llvm::MemoryBufferRef Buffer, llvm::BitstreamReader &StreamFile) const {
StreamFile.init((const unsigned char *)Buffer.getBufferStart(),
(const unsigned char *)Buffer.getBufferEnd());
}

PCHContainerOperations::PCHContainerOperations() {
registerWriter(llvm::make_unique<RawPCHContainerWriter>());
registerReader(llvm::make_unique<RawPCHContainerReader>());
}
4 changes: 3 additions & 1 deletion clang/lib/Lex/HeaderSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "clang/Lex/HeaderSearch.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Frontend/PCHContainerOperations.h"
#include "clang/Lex/ExternalPreprocessorSource.h"
#include "clang/Lex/HeaderMap.h"
#include "clang/Lex/HeaderSearchOptions.h"
Expand Down Expand Up @@ -151,7 +152,8 @@ std::string HeaderSearch::getModuleFileName(StringRef ModuleName,
auto FileName = llvm::sys::path::filename(ModuleMapPath);

llvm::hash_code Hash =
llvm::hash_combine(DirName.lower(), FileName.lower());
llvm::hash_combine(DirName.lower(), FileName.lower(),
HSOpts->ModuleFormat);

SmallString<128> HashStr;
llvm::APInt(64, size_t(Hash)).toStringUnsigned(HashStr, /*Radix*/36);
Expand Down
20 changes: 10 additions & 10 deletions clang/lib/Serialization/ASTReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3601,7 +3601,7 @@ ASTReader::ReadASTCore(StringRef FileName,

ModuleFile &F = *M;
BitstreamCursor &Stream = F.Stream;
PCHContainerOps.ExtractPCH(F.Buffer->getMemBufferRef(), F.StreamFile);
PCHContainerRdr.ExtractPCH(F.Buffer->getMemBufferRef(), F.StreamFile);
Stream.init(&F.StreamFile);
F.SizeInBits = F.Buffer->getBufferSize() * 8;

Expand Down Expand Up @@ -3872,7 +3872,7 @@ static ASTFileSignature readASTFileSignature(llvm::BitstreamReader &StreamFile){
/// file.
std::string ASTReader::getOriginalSourceFile(
const std::string &ASTFileName, FileManager &FileMgr,
const PCHContainerOperations &PCHContainerOps, DiagnosticsEngine &Diags) {
const PCHContainerReader &PCHContainerRdr, DiagnosticsEngine &Diags) {
// Open the AST file.
auto Buffer = FileMgr.getBufferForFile(ASTFileName);
if (!Buffer) {
Expand All @@ -3883,7 +3883,7 @@ std::string ASTReader::getOriginalSourceFile(

// Initialize the stream
llvm::BitstreamReader StreamFile;
PCHContainerOps.ExtractPCH((*Buffer)->getMemBufferRef(), StreamFile);
PCHContainerRdr.ExtractPCH((*Buffer)->getMemBufferRef(), StreamFile);
BitstreamCursor Stream(StreamFile);

// Sniff for the signature.
Expand Down Expand Up @@ -3967,7 +3967,7 @@ namespace {

bool ASTReader::readASTFileControlBlock(
StringRef Filename, FileManager &FileMgr,
const PCHContainerOperations &PCHContainerOps,
const PCHContainerReader &PCHContainerRdr,
ASTReaderListener &Listener) {
// Open the AST file.
// FIXME: This allows use of the VFS; we do not allow use of the
Expand All @@ -3979,7 +3979,7 @@ bool ASTReader::readASTFileControlBlock(

// Initialize the stream
llvm::BitstreamReader StreamFile;
PCHContainerOps.ExtractPCH((*Buffer)->getMemBufferRef(), StreamFile);
PCHContainerRdr.ExtractPCH((*Buffer)->getMemBufferRef(), StreamFile);
BitstreamCursor Stream(StreamFile);

// Sniff for the signature.
Expand Down Expand Up @@ -4160,12 +4160,12 @@ bool ASTReader::readASTFileControlBlock(

bool ASTReader::isAcceptableASTFile(
StringRef Filename, FileManager &FileMgr,
const PCHContainerOperations &PCHContainerOps, const LangOptions &LangOpts,
const PCHContainerReader &PCHContainerRdr, const LangOptions &LangOpts,
const TargetOptions &TargetOpts, const PreprocessorOptions &PPOpts,
std::string ExistingModuleCachePath) {
SimplePCHValidator validator(LangOpts, TargetOpts, PPOpts,
ExistingModuleCachePath, FileMgr);
return !readASTFileControlBlock(Filename, FileMgr, PCHContainerOps,
return !readASTFileControlBlock(Filename, FileMgr, PCHContainerRdr,
validator);
}

Expand Down Expand Up @@ -8472,17 +8472,17 @@ void ASTReader::pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name) {
}

ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context,
const PCHContainerOperations &PCHContainerOps,
const PCHContainerReader &PCHContainerRdr,
StringRef isysroot, bool DisableValidation,
bool AllowASTWithCompilerErrors,
bool AllowConfigurationMismatch, bool ValidateSystemInputs,
bool UseGlobalIndex,
std::unique_ptr<llvm::Timer> ReadTimer)
: Listener(new PCHValidator(PP, *this)), DeserializationListener(nullptr),
OwnsDeserializationListener(false), SourceMgr(PP.getSourceManager()),
FileMgr(PP.getFileManager()), PCHContainerOps(PCHContainerOps),
FileMgr(PP.getFileManager()), PCHContainerRdr(PCHContainerRdr),
Diags(PP.getDiagnostics()), SemaObj(nullptr), PP(PP), Context(Context),
Consumer(nullptr), ModuleMgr(PP.getFileManager(), PCHContainerOps),
Consumer(nullptr), ModuleMgr(PP.getFileManager(), PCHContainerRdr),
ReadTimer(std::move(ReadTimer)),
isysroot(isysroot), DisableValidation(DisableValidation),
AllowASTWithCompilerErrors(AllowASTWithCompilerErrors),
Expand Down
12 changes: 6 additions & 6 deletions clang/lib/Serialization/GlobalModuleIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ namespace {
/// \brief Builder that generates the global module index file.
class GlobalModuleIndexBuilder {
FileManager &FileMgr;
const PCHContainerOperations &PCHContainerOps;
const PCHContainerReader &PCHContainerRdr;

/// \brief Mapping from files to module file information.
typedef llvm::MapVector<const FileEntry *, ModuleFileInfo> ModuleFilesMap;
Expand Down Expand Up @@ -419,8 +419,8 @@ namespace {

public:
explicit GlobalModuleIndexBuilder(
FileManager &FileMgr, const PCHContainerOperations &PCHContainerOps)
: FileMgr(FileMgr), PCHContainerOps(PCHContainerOps) {}
FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr)
: FileMgr(FileMgr), PCHContainerRdr(PCHContainerRdr) {}

/// \brief Load the contents of the given module file into the builder.
///
Expand Down Expand Up @@ -505,7 +505,7 @@ bool GlobalModuleIndexBuilder::loadModuleFile(const FileEntry *File) {

// Initialize the input stream
llvm::BitstreamReader InStreamFile;
PCHContainerOps.ExtractPCH((*Buffer)->getMemBufferRef(), InStreamFile);
PCHContainerRdr.ExtractPCH((*Buffer)->getMemBufferRef(), InStreamFile);
llvm::BitstreamCursor InStream(InStreamFile);

// Sniff for the signature.
Expand Down Expand Up @@ -768,7 +768,7 @@ void GlobalModuleIndexBuilder::writeIndex(llvm::BitstreamWriter &Stream) {

GlobalModuleIndex::ErrorCode
GlobalModuleIndex::writeIndex(FileManager &FileMgr,
const PCHContainerOperations &PCHContainerOps,
const PCHContainerReader &PCHContainerRdr,
StringRef Path) {
llvm::SmallString<128> IndexPath;
IndexPath += Path;
Expand All @@ -792,7 +792,7 @@ GlobalModuleIndex::writeIndex(FileManager &FileMgr,
}

// The module index builder.
GlobalModuleIndexBuilder Builder(FileMgr, PCHContainerOps);
GlobalModuleIndexBuilder Builder(FileMgr, PCHContainerRdr);

// Load each of the module files.
std::error_code EC;
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Serialization/ModuleManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
}

// Initialize the stream.
PCHContainerOps.ExtractPCH(New->Buffer->getMemBufferRef(), New->StreamFile);
PCHContainerRdr.ExtractPCH(New->Buffer->getMemBufferRef(), New->StreamFile);
}

if (ExpectedSignature) {
Expand Down Expand Up @@ -290,8 +290,8 @@ void ModuleManager::moduleFileAccepted(ModuleFile *MF) {
}

ModuleManager::ModuleManager(FileManager &FileMgr,
const PCHContainerOperations &PCHContainerOps)
: FileMgr(FileMgr), PCHContainerOps(PCHContainerOps), GlobalIndex(),
const PCHContainerReader &PCHContainerRdr)
: FileMgr(FileMgr), PCHContainerRdr(PCHContainerRdr), GlobalIndex(),
FirstVisitState(nullptr) {}

ModuleManager::~ModuleManager() {
Expand Down
11 changes: 7 additions & 4 deletions clang/test/Modules/pch_container.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
@import DependsOnModule;
// REQUIRES: x86-registered-target
// RUN: rm -rf %t-MachO %t-ELF %t-ELF_SPLIT %t-COFF
// RUN: %clang_cc1 -triple=x86_64-apple-darwin -fmodules -fimplicit-module-maps -fdisable-module-hash -fmodules-cache-path=%t-MachO -F %S/Inputs %s
// RUN: %clang_cc1 -triple=x86_64-linux-elf -fmodules -fimplicit-module-maps -fdisable-module-hash -fmodules-cache-path=%t-ELF -F %S/Inputs %s
// RUN: %clang_cc1 -triple=x86_64-windows-coff -fmodules -fimplicit-module-maps -fdisable-module-hash -fmodules-cache-path=%t-COFF -F %S/Inputs %s
// RUN: rm -rf %t-MachO %t-ELF %t-ELF_SPLIT %t-COFF %t-raw
// RUN: %clang_cc1 -triple=x86_64-apple-darwin -fmodules -fmodule-format=obj -fimplicit-module-maps -fdisable-module-hash -fmodules-cache-path=%t-MachO -F %S/Inputs %s
// RUN: %clang_cc1 -triple=x86_64-linux-elf -fmodules -fmodule-format=obj -fimplicit-module-maps -fdisable-module-hash -fmodules-cache-path=%t-ELF -F %S/Inputs %s
// RUN: %clang_cc1 -triple=x86_64-windows-coff -fmodules -fmodule-format=obj -fimplicit-module-maps -fdisable-module-hash -fmodules-cache-path=%t-COFF -F %S/Inputs %s
// RUN: %clang_cc1 -triple=x86_64-apple-darwin -fmodules -fmodule-format=raw -fimplicit-module-maps -fdisable-module-hash -fmodules-cache-path=%t-raw -F %S/Inputs %s


// RUN: llvm-objdump -section-headers %t-MachO/DependsOnModule.pcm %t-ELF/DependsOnModule.pcm %t-COFF/DependsOnModule.pcm | FileCheck %s
// CHECK: file format Mach-O 64-bit x86-64
Expand All @@ -13,5 +15,6 @@
// CHECK: file format COFF-x86-64
// CHECK: clangast {{[0-9a-f]+}} {{[0-9a-f]+}}

// RUN: not llvm-objdump -section-headers %t-raw/DependsOnModule.pcm

// RUN: %clang_cc1 -split-dwarf-file t-split.dwo -triple=x86_64-linux-elf -fmodules -fimplicit-module-maps -fdisable-module-hash -fmodules-cache-path=%t-ELF_SPLIT -F %S/Inputs %s -o %t-split.o
6 changes: 3 additions & 3 deletions clang/tools/arcmt-test/arcmt-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static bool checkForMigration(StringRef resourcesPath,
return false;

arcmt::checkForManualIssues(CI, CI.getFrontendOpts().Inputs[0],
std::make_shared<RawPCHContainerOperations>(),
std::make_shared<PCHContainerOperations>(),
Diags->getClient());
return Diags->getClient()->getNumErrors() > 0;
}
Expand Down Expand Up @@ -171,8 +171,8 @@ static bool performTransformations(StringRef resourcesPath,
if (!origCI.getLangOpts()->ObjC1)
return false;

MigrationProcess migration(
origCI, std::make_shared<RawPCHContainerOperations>(), DiagClient);
MigrationProcess migration(origCI, std::make_shared<PCHContainerOperations>(),
DiagClient);

std::vector<TransformFn>
transforms = arcmt::getAllTransformations(origCI.getLangOpts()->getGC(),
Expand Down
1 change: 0 additions & 1 deletion clang/tools/clang-check/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ add_clang_executable(clang-check
target_link_libraries(clang-check
clangAST
clangBasic
clangCodeGen
clangDriver
clangFrontend
clangRewriteFrontend
Expand Down
3 changes: 1 addition & 2 deletions clang/tools/clang-check/ClangCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ int main(int argc, const char **argv) {

CommonOptionsParser OptionsParser(argc, argv, ClangCheckCategory);
ClangTool Tool(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList(),
std::make_shared<clang::ObjectFilePCHContainerOperations>());
OptionsParser.getSourcePathList());

// Clear adjusters because -fsyntax-only is inserted by the default chain.
Tool.clearArgumentsAdjusters();
Expand Down
8 changes: 6 additions & 2 deletions clang/tools/driver/cc1_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ void initializePollyPasses(llvm::PassRegistry &Registry);
#endif

int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
std::unique_ptr<CompilerInstance> Clang(new CompilerInstance(
std::make_shared<ObjectFilePCHContainerOperations>()));
std::unique_ptr<CompilerInstance> Clang(new CompilerInstance());
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());

// Register the support for object-file-wrapped Clang modules.
auto PCHOps = Clang->getPCHContainerOperations();
PCHOps->registerWriter(llvm::make_unique<ObjectFilePCHContainerWriter>());
PCHOps->registerReader(llvm::make_unique<ObjectFilePCHContainerReader>());

// Initialize targets first, so that --version shows registered targets.
llvm::InitializeAllTargets();
llvm::InitializeAllTargetMCs();
Expand Down
8 changes: 4 additions & 4 deletions clang/tools/libclang/CIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2884,8 +2884,8 @@ CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
llvm::InitializeAllAsmPrinters();
llvm::InitializeAllAsmParsers();

CIndexer *CIdxr =
new CIndexer(std::make_shared<ObjectFilePCHContainerOperations>());
CIndexer *CIdxr = new CIndexer();

if (excludeDeclarationsFromPCH)
CIdxr->setOnlyLocalDecls();
if (displayDiagnostics)
Expand Down Expand Up @@ -2954,8 +2954,8 @@ enum CXErrorCode clang_createTranslationUnit2(CXIndex CIdx,
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
CompilerInstance::createDiagnostics(new DiagnosticOptions());
std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile(
ast_filename, CXXIdx->getPCHContainerOperations(), Diags, FileSystemOpts,
CXXIdx->getOnlyLocalDecls(), None,
ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(), Diags,
FileSystemOpts, CXXIdx->getOnlyLocalDecls(), None,
/*CaptureDiagnostics=*/true,
/*AllowPCHWithCompilerErrors=*/true,
/*UserFilesAreVolatile=*/true);
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/libclang/CIndexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CIndexer {

public:
CIndexer(std::shared_ptr<PCHContainerOperations> PCHContainerOps =
std::make_shared<RawPCHContainerOperations>())
std::make_shared<PCHContainerOperations>())
: OnlyLocalDecls(false), DisplayDiagnostics(false),
Options(CXGlobalOpt_None), PCHContainerOps(PCHContainerOps) {}

Expand Down
1 change: 0 additions & 1 deletion clang/tools/libclang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ set(SOURCES
set(LIBS
clangAST
clangBasic
clangCodeGen
clangFrontend
clangIndex
clangLex
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/ASTMatchers/ASTMatchersTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ testing::AssertionResult matchesConditionally(
Args.push_back("-frtti");
Args.push_back("-fexceptions");
if (!runToolOnCodeWithArgs(Factory->create(), Code, Args, Filename,
std::make_shared<RawPCHContainerOperations>(),
std::make_shared<PCHContainerOperations>(),
VirtualMappedFiles)) {
return testing::AssertionFailure() << "Parsing error in \"" << Code << "\"";
}
Expand Down