Skip to content

Commit

Permalink
[deserialization] Expose ModuleFile::error and use the method in SILD…
Browse files Browse the repository at this point in the history
…eserializer to mark a module as being malformed when invalid SIL is encountered.

Swift SVN r14703
  • Loading branch information
gottesmm committed Mar 6, 2014
1 parent 84c9eb0 commit 2aa197f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions include/swift/Serialization/ModuleFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,16 @@ class ModuleFile : public LazyMemberLoader {
/// Constructs an new module and validates it.
ModuleFile(std::unique_ptr<llvm::MemoryBuffer> input, bool isFramework);

/// Convenience function for module loading.
public:
/// Change the status of the current module. Default argument marks the module
/// as being malformed.
void error(ModuleStatus issue = ModuleStatus::Malformed) {
assert(issue != ModuleStatus::Valid);
assert((!FileContext || issue != ModuleStatus::Malformed) &&
"error deserializing an individual record");
setStatus(issue);
}

public:
ASTContext &getContext() const {
assert(FileContext && "no associated context yet");
return FileContext->getParentModule()->Ctx;
Expand Down
6 changes: 6 additions & 0 deletions lib/Serialization/DeserializeSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ SILFunction *SILDeserializer::readSILFunction(DeclID FID,
auto entry = SILCursor.advance(AF_DontPopBlockAtEnd);
if (entry.Kind == llvm::BitstreamEntry::Error) {
DEBUG(llvm::dbgs() << "Cursor advance error in readSILFunction.\n");
MF->error();
return nullptr;
}

Expand All @@ -387,18 +388,21 @@ SILFunction *SILDeserializer::readSILFunction(DeclID FID,

if (funcTyID == 0) {
DEBUG(llvm::dbgs() << "SILFunction typeID is 0.\n");
MF->error();
return nullptr;
}
auto ty = getSILType(MF->getType(funcTyID), SILValueCategory::Object);
if (!ty.is<SILFunctionType>()) {
DEBUG(llvm::dbgs() << "not a function type for SILFunction\n");
MF->error();
return nullptr;
}

auto linkage = fromStableSILLinkage(rawLinkage);
if (!linkage) {
DEBUG(llvm::dbgs() << "invalid linkage code " << rawLinkage
<< " for SILFunction\n");
MF->error();
return nullptr;
}

Expand All @@ -414,6 +418,7 @@ SILFunction *SILDeserializer::readSILFunction(DeclID FID,
if (fn) {
if (fn->getLoweredType() != ty) {
DEBUG(llvm::dbgs() << "SILFunction type mismatch.\n");
MF->error();
return nullptr;
}

Expand Down Expand Up @@ -493,6 +498,7 @@ SILFunction *SILDeserializer::readSILFunction(DeclID FID,
// Handle a SILInstruction record.
if (readSILInstruction(fn, CurrentBB, kind, scratch)) {
DEBUG(llvm::dbgs() << "readSILInstruction returns error.\n");
MF->error();
return fn;
}
}
Expand Down

0 comments on commit 2aa197f

Please sign in to comment.