aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Serialization/ASTBitCodes.h14
-rw-r--r--lib/Frontend/FrontendActions.cpp18
-rw-r--r--lib/Serialization/ASTReader.cpp4
-rw-r--r--lib/Serialization/ASTWriter.cpp5
4 files changed, 23 insertions, 18 deletions
diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h
index 8c58fb2816..569d31d759 100644
--- a/include/clang/Serialization/ASTBitCodes.h
+++ b/include/clang/Serialization/ASTBitCodes.h
@@ -259,21 +259,25 @@ namespace clang {
/// \brief The directory that the PCH was originally created in.
ORIGINAL_PCH_DIR = 6,
+ /// \brief Record code for file ID of the file or buffer that was used to
+ /// generate the AST file.
+ ORIGINAL_FILE_ID = 7,
+
/// \brief Offsets into the input-files block where input files
/// reside.
- INPUT_FILE_OFFSETS = 7,
+ INPUT_FILE_OFFSETS = 8,
/// \brief Record code for the diagnostic options table.
- DIAGNOSTIC_OPTIONS = 8,
+ DIAGNOSTIC_OPTIONS = 9,
/// \brief Record code for the filesystem options table.
- FILE_SYSTEM_OPTIONS = 9,
+ FILE_SYSTEM_OPTIONS = 10,
/// \brief Record code for the headers search options table.
- HEADER_SEARCH_OPTIONS = 10,
+ HEADER_SEARCH_OPTIONS = 11,
/// \brief Record code for the preprocessor options table.
- PREPROCESSOR_OPTIONS = 11
+ PREPROCESSOR_OPTIONS = 12
};
/// \brief Record types that occur within the input-files block
diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp
index 47063f78b5..c28593f92a 100644
--- a/lib/Frontend/FrontendActions.cpp
+++ b/lib/Frontend/FrontendActions.cpp
@@ -273,19 +273,11 @@ bool GenerateModuleAction::BeginSourceFileAction(CompilerInstance &CI,
CI.getPreprocessor().getHeaderSearchInfo().getModuleMap(),
Module, HeaderContents);
- StringRef InputName = Module::getModuleInputBufferName();
-
- // We consistently construct a buffer as input to build the module.
- // This means the main file for modules will always be a virtual one.
- // FIXME: Maybe allow using a memory buffer as input directly instead of
- // messing with virtual files.
- const FileEntry *HeaderFile = FileMgr.getVirtualFile(InputName,
- HeaderContents.size(),
- time(0));
- llvm::MemoryBuffer *HeaderContentsBuf
- = llvm::MemoryBuffer::getMemBufferCopy(HeaderContents);
- CI.getSourceManager().overrideFileContents(HeaderFile, HeaderContentsBuf);
- setCurrentInput(FrontendInputFile(InputName, getCurrentFileKind(),
+ llvm::MemoryBuffer *InputBuffer =
+ llvm::MemoryBuffer::getMemBufferCopy(HeaderContents,
+ Module::getModuleInputBufferName());
+ // Ownership of InputBuffer will be transfered to the SourceManager.
+ setCurrentInput(FrontendInputFile(InputBuffer, getCurrentFileKind(),
Module->IsSystem));
return true;
}
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index cd15e212dd..6e82cd9c76 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -1796,6 +1796,10 @@ ASTReader::ReadControlBlock(ModuleFile &F,
MaybeAddSystemRootToFilename(F, F.OriginalSourceFileName);
break;
+ case ORIGINAL_FILE_ID:
+ F.OriginalSourceFileID = FileID::get(Record[0]);
+ break;
+
case ORIGINAL_PCH_DIR:
F.OriginalDir.assign(BlobStart, BlobLen);
break;
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp
index f06b428019..744ae9fd81 100644
--- a/lib/Serialization/ASTWriter.cpp
+++ b/lib/Serialization/ASTWriter.cpp
@@ -777,6 +777,7 @@ void ASTWriter::WriteBlockInfoBlock() {
RECORD(TARGET_OPTIONS);
RECORD(ORIGINAL_FILE);
RECORD(ORIGINAL_PCH_DIR);
+ RECORD(ORIGINAL_FILE_ID);
RECORD(INPUT_FILE_OFFSETS);
RECORD(DIAGNOSTIC_OPTIONS);
RECORD(FILE_SYSTEM_OPTIONS);
@@ -1180,6 +1181,10 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
Stream.EmitRecordWithBlob(FileAbbrevCode, Record, MainFileNameStr);
}
+ Record.clear();
+ Record.push_back(SM.getMainFileID().getOpaqueValue());
+ Stream.EmitRecord(ORIGINAL_FILE_ID, Record);
+
// Original PCH directory
if (!OutputFile.empty() && OutputFile != "-") {
BitCodeAbbrev *Abbrev = new BitCodeAbbrev();