r293393 - Modules: Separate out a checkSignature helper, almost NFC
Duncan P. N. Exon Smith via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 28 13:34:28 PST 2017
Author: dexonsmith
Date: Sat Jan 28 15:34:28 2017
New Revision: 293393
URL: http://llvm.org/viewvc/llvm-project?rev=293393&view=rev
Log:
Modules: Separate out a checkSignature helper, almost NFC
The main point is to move the delete-the-new-module logic into the same block
that creates it, so I can simplify the memory management in a follow-up, but I
think it's clearer to use use a checkSignature helper here anyway.
There is a minor functionality change: we now scan ahead to pull the signature
out of the control block *only* if this is a new ModuleFile. For old ones,
ASTReader::ReadControlBlock will have already read the signature.
Modified:
cfe/trunk/lib/Serialization/ModuleManager.cpp
Modified: cfe/trunk/lib/Serialization/ModuleManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ModuleManager.cpp?rev=293393&r1=293392&r2=293393&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ModuleManager.cpp (original)
+++ cfe/trunk/lib/Serialization/ModuleManager.cpp Sat Jan 28 15:34:28 2017
@@ -52,6 +52,17 @@ ModuleManager::lookupBuffer(StringRef Na
return std::move(InMemoryBuffers[Entry]);
}
+static bool checkSignature(ASTFileSignature Signature,
+ ASTFileSignature ExpectedSignature,
+ std::string &ErrorStr) {
+ if (!ExpectedSignature || Signature == ExpectedSignature)
+ return false;
+
+ ErrorStr =
+ Signature ? "signature mismatch" : "could not read module signature";
+ return true;
+}
+
ModuleManager::AddModuleResult
ModuleManager::addModule(StringRef FileName, ModuleKind Type,
SourceLocation ImportLoc, ModuleFile *ImportedBy,
@@ -136,22 +147,14 @@ ModuleManager::addModule(StringRef FileN
// Initialize the stream.
ModuleEntry->Data = PCHContainerRdr.ExtractPCH(*ModuleEntry->Buffer);
- }
- if (ExpectedSignature) {
- // If we've not read the control block yet, read the signature eagerly now
- // so that we can check it.
- if (!ModuleEntry->Signature)
- ModuleEntry->Signature = ReadSignature(ModuleEntry->Data);
-
- if (ModuleEntry->Signature != ExpectedSignature) {
- ErrorStr = ModuleEntry->Signature ? "signature mismatch"
- : "could not read module signature";
-
- if (NewModule)
- delete ModuleEntry;
+ // Read the signature eagerly now so that we can check it.
+ if (checkSignature(ReadSignature(ModuleEntry->Data), ExpectedSignature, ErrorStr)) {
+ delete ModuleEntry;
return OutOfDate;
}
+ } else if (checkSignature(ModuleEntry->Signature, ExpectedSignature, ErrorStr)) {
+ return OutOfDate;
}
if (ImportedBy) {
More information about the cfe-commits
mailing list