[global-variable] When deserializing global variables, only deserialize if the current module does not have a gv with the same name.

This is testing by deserialization not blowing up.

<rdar://problem/18562242>

Swift SVN r22555
This commit is contained in:
Michael Gottesman
2014-10-06 23:16:53 +00:00
parent 1bd44a82a6
commit 652f875b21
2 changed files with 20 additions and 7 deletions

View File

@@ -333,6 +333,18 @@ SILFunction *SILDeserializer::getFuncForReference(StringRef name) {
return readSILFunction(*iter, nullptr, name, /*declarationOnly*/ true);
}
/// Helper function to find a SILGlobalVariable given its name. It first checks
/// in the module. If we can not find it in the module, we attempt to
/// deserialize it.
SILGlobalVariable *SILDeserializer::getGlobalForReference(StringRef name) {
// Check to see if we have a global by this name already.
if (SILGlobalVariable *g = SILMod.lookUpGlobalVariable(name))
return g;
// Otherwise, look for a global with this name in the module.
return readGlobalVar(name);
}
/// Deserialize a SILFunction if it is not already deserialized. The input
/// SILFunction can either be an empty declaration or null. If it is an empty
/// declaration, we fill in the contents. If the input SILFunction is
@@ -918,7 +930,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
Identifier Name = MF->getIdentifier(ValID);
// Find the global variable.
SILGlobalVariable *g = readGlobalVar(Name.str());
SILGlobalVariable *g = getGlobalForReference(Name.str());
assert(g && "Can't deserialize global variable");
assert(g->getLoweredType().getAddressType() ==
getSILType(Ty, (SILValueCategory)TyCategory) &&

View File

@@ -93,6 +93,7 @@ namespace swift {
SILFunction *getFuncForReference(StringRef Name);
SILFunction *lookupSILFunction(StringRef Name);
SILVTable *readVTable(serialization::DeclID);
SILGlobalVariable *getGlobalForReference(StringRef Name);
SILGlobalVariable *readGlobalVar(StringRef Name);
SILWitnessTable *readWitnessTable(serialization::DeclID,
SILWitnessTable *existingWt,