mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -333,6 +333,18 @@ SILFunction *SILDeserializer::getFuncForReference(StringRef name) {
|
|||||||
return readSILFunction(*iter, nullptr, name, /*declarationOnly*/ true);
|
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
|
/// 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
|
/// 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
|
/// declaration, we fill in the contents. If the input SILFunction is
|
||||||
@@ -756,14 +768,14 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
|
|||||||
ONEOPERAND_ONETYPE_INST(ConvertFunction)
|
ONEOPERAND_ONETYPE_INST(ConvertFunction)
|
||||||
ONEOPERAND_ONETYPE_INST(ProjectBlockStorage)
|
ONEOPERAND_ONETYPE_INST(ProjectBlockStorage)
|
||||||
#undef ONEOPERAND_ONETYPE_INST
|
#undef ONEOPERAND_ONETYPE_INST
|
||||||
|
|
||||||
case ValueKind::ObjCProtocolInst: {
|
case ValueKind::ObjCProtocolInst: {
|
||||||
auto Ty = getSILType(MF->getType(TyID), (SILValueCategory)TyCategory);
|
auto Ty = getSILType(MF->getType(TyID), (SILValueCategory)TyCategory);
|
||||||
auto Proto = MF->getDecl(ValID);
|
auto Proto = MF->getDecl(ValID);
|
||||||
ResultVal = Builder.createObjCProtocol(Loc, cast<ProtocolDecl>(Proto), Ty);
|
ResultVal = Builder.createObjCProtocol(Loc, cast<ProtocolDecl>(Proto), Ty);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ValueKind::InitExistentialInst:
|
case ValueKind::InitExistentialInst:
|
||||||
case ValueKind::InitExistentialRefInst: {
|
case ValueKind::InitExistentialRefInst: {
|
||||||
|
|
||||||
@@ -918,7 +930,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
|
|||||||
Identifier Name = MF->getIdentifier(ValID);
|
Identifier Name = MF->getIdentifier(ValID);
|
||||||
|
|
||||||
// Find the global variable.
|
// Find the global variable.
|
||||||
SILGlobalVariable *g = readGlobalVar(Name.str());
|
SILGlobalVariable *g = getGlobalForReference(Name.str());
|
||||||
assert(g && "Can't deserialize global variable");
|
assert(g && "Can't deserialize global variable");
|
||||||
assert(g->getLoweredType().getAddressType() ==
|
assert(g->getLoweredType().getAddressType() ==
|
||||||
getSILType(Ty, (SILValueCategory)TyCategory) &&
|
getSILType(Ty, (SILValueCategory)TyCategory) &&
|
||||||
@@ -1487,17 +1499,17 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
|
|||||||
"expected 6 values for InitBlockStorageHeader");
|
"expected 6 values for InitBlockStorageHeader");
|
||||||
SILType blockTy
|
SILType blockTy
|
||||||
= getSILType(MF->getType(TyID), (SILValueCategory)TyCategory);
|
= getSILType(MF->getType(TyID), (SILValueCategory)TyCategory);
|
||||||
|
|
||||||
SILType storageTy = getSILType(MF->getType(ListOfValues[2]),
|
SILType storageTy = getSILType(MF->getType(ListOfValues[2]),
|
||||||
SILValueCategory::Address);
|
SILValueCategory::Address);
|
||||||
SILValue storage
|
SILValue storage
|
||||||
= getLocalValue(ListOfValues[0], ListOfValues[1], storageTy);
|
= getLocalValue(ListOfValues[0], ListOfValues[1], storageTy);
|
||||||
|
|
||||||
SILType invokeTy = getSILType(MF->getType(ListOfValues[5]),
|
SILType invokeTy = getSILType(MF->getType(ListOfValues[5]),
|
||||||
SILValueCategory::Object);
|
SILValueCategory::Object);
|
||||||
SILValue invoke
|
SILValue invoke
|
||||||
= getLocalValue(ListOfValues[3], ListOfValues[4], invokeTy);
|
= getLocalValue(ListOfValues[3], ListOfValues[4], invokeTy);
|
||||||
|
|
||||||
ResultVal = Builder.createInitBlockStorageHeader(Loc, storage, invoke,
|
ResultVal = Builder.createInitBlockStorageHeader(Loc, storage, invoke,
|
||||||
blockTy);
|
blockTy);
|
||||||
break;
|
break;
|
||||||
@@ -1763,7 +1775,7 @@ SILWitnessTable *SILDeserializer::readWitnessTable(DeclID WId,
|
|||||||
MF->error();
|
MF->error();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Linkage = fromStableSILLinkage(RawLinkage);
|
auto Linkage = fromStableSILLinkage(RawLinkage);
|
||||||
if (!Linkage) {
|
if (!Linkage) {
|
||||||
DEBUG(llvm::dbgs() << "invalid linkage code " << RawLinkage
|
DEBUG(llvm::dbgs() << "invalid linkage code " << RawLinkage
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ namespace swift {
|
|||||||
SILFunction *getFuncForReference(StringRef Name);
|
SILFunction *getFuncForReference(StringRef Name);
|
||||||
SILFunction *lookupSILFunction(StringRef Name);
|
SILFunction *lookupSILFunction(StringRef Name);
|
||||||
SILVTable *readVTable(serialization::DeclID);
|
SILVTable *readVTable(serialization::DeclID);
|
||||||
|
SILGlobalVariable *getGlobalForReference(StringRef Name);
|
||||||
SILGlobalVariable *readGlobalVar(StringRef Name);
|
SILGlobalVariable *readGlobalVar(StringRef Name);
|
||||||
SILWitnessTable *readWitnessTable(serialization::DeclID,
|
SILWitnessTable *readWitnessTable(serialization::DeclID,
|
||||||
SILWitnessTable *existingWt,
|
SILWitnessTable *existingWt,
|
||||||
|
|||||||
Reference in New Issue
Block a user