Skip to content

Commit

Permalink
Merge pull request #40729 from xymus/sil-deser-prints
Browse files Browse the repository at this point in the history
[Serialization/SIL] Print error messages in the pretty stacktrace
  • Loading branch information
xymus committed Jan 5, 2022
2 parents cc12c4e + d270593 commit 5a2f911
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
41 changes: 15 additions & 26 deletions lib/Serialization/DeserializeSIL.cpp
Expand Up @@ -506,8 +506,7 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
return maybeEntry.takeError();
llvm::BitstreamEntry entry = maybeEntry.get();
if (entry.Kind == llvm::BitstreamEntry::Error) {
LLVM_DEBUG(llvm::dbgs() << "Cursor advance error in readSILFunction.\n");
MF->fatal();
MF->fatal("Cursor advance error in readSILFunction");
}

SmallVector<uint64_t, 64> scratch;
Expand Down Expand Up @@ -541,8 +540,7 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
genericSigID, clangNodeOwnerID, SemanticsIDs);

if (funcTyID == 0) {
LLVM_DEBUG(llvm::dbgs() << "SILFunction typeID is 0.\n");
MF->fatal();
MF->fatal("SILFunction typeID is 0");
}
auto astType = MF->getTypeChecked(funcTyID);
if (!astType) {
Expand All @@ -555,8 +553,7 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
}
auto ty = getSILType(astType.get(), SILValueCategory::Object, nullptr);
if (!ty.is<SILFunctionType>()) {
LLVM_DEBUG(llvm::dbgs() << "not a function type for SILFunction\n");
MF->fatal();
MF->fatal("not a function type for SILFunction");
}

SILFunction *replacedFunction = nullptr;
Expand All @@ -574,16 +571,15 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
if (!linkageOpt) {
LLVM_DEBUG(llvm::dbgs() << "invalid linkage code " << rawLinkage
<< " for SILFunction\n");
MF->fatal();
MF->fatal("invalid linkage code");
}
SILLinkage linkage = linkageOpt.getValue();

ValueDecl *clangNodeOwner = nullptr;
if (clangNodeOwnerID != 0) {
clangNodeOwner = dyn_cast_or_null<ValueDecl>(MF->getDecl(clangNodeOwnerID));
if (!clangNodeOwner) {
LLVM_DEBUG(llvm::dbgs() << "invalid clang node owner for SILFunction\n");
MF->fatal();
MF->fatal("invalid clang node owner for SILFunction");
}
}

Expand All @@ -606,8 +602,7 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
// If we have an existing function, verify that the types match up.
if (fn) {
if (fn->getLoweredType() != ty) {
LLVM_DEBUG(llvm::dbgs() << "SILFunction type mismatch.\n");
MF->fatal();
MF->fatal("SILFunction type mismatch");
}

fn->setSerialized(IsSerialized_t(isSerialized));
Expand Down Expand Up @@ -642,8 +637,7 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
}

if (fn->isDynamicallyReplaceable() != isDynamic) {
LLVM_DEBUG(llvm::dbgs() << "SILFunction type mismatch.\n");
MF->fatal();
MF->fatal("SILFunction type mismatch");
}

} else {
Expand Down Expand Up @@ -840,8 +834,7 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,

// Handle a SILInstruction record.
if (readSILInstruction(fn, Builder, kind, scratch)) {
LLVM_DEBUG(llvm::dbgs() << "readSILInstruction returns error.\n");
MF->fatal();
MF->fatal("readSILInstruction returns error");
}
}

Expand Down Expand Up @@ -2936,8 +2929,7 @@ bool SILDeserializer::hasSILFunction(StringRef Name,
MF->fatal(maybeEntry.takeError());
llvm::BitstreamEntry entry = maybeEntry.get();
if (entry.Kind == llvm::BitstreamEntry::Error) {
LLVM_DEBUG(llvm::dbgs() << "Cursor advance error in hasSILFunction.\n");
MF->fatal();
MF->fatal("Cursor advance error in hasSILFunction");
}

SmallVector<uint64_t, 64> scratch;
Expand Down Expand Up @@ -3113,8 +3105,7 @@ SILGlobalVariable *SILDeserializer::readGlobalVar(StringRef Name) {
while (kind != SIL_FUNCTION && kind != SIL_VTABLE && kind != SIL_GLOBALVAR &&
kind != SIL_WITNESS_TABLE && kind != SIL_DIFFERENTIABILITY_WITNESS) {
if (readSILInstruction(nullptr, Builder, kind, scratch)) {
LLVM_DEBUG(llvm::dbgs() << "readSILInstruction returns error.\n");
MF->fatal();
MF->fatal("readSILInstruction returns error");
}

// Fetch the next record.
Expand Down Expand Up @@ -3496,7 +3487,7 @@ llvm::Expected<SILWitnessTable *>
if (!Linkage) {
LLVM_DEBUG(llvm::dbgs() << "invalid linkage code " << RawLinkage
<< " for SILFunction\n");
MF->fatal();
MF->fatal("invalid linkage code");
}

// Deserialize Conformance.
Expand All @@ -3518,8 +3509,7 @@ llvm::Expected<SILWitnessTable *>
// up.
if (wT) {
if (wT->getConformance() != theConformance) {
LLVM_DEBUG(llvm::dbgs() << "Conformance mismatch.\n");
MF->fatal();
MF->fatal("Conformance mismatch");
}

// Don't override the linkage of a witness table with an existing
Expand Down Expand Up @@ -3663,13 +3653,13 @@ readDefaultWitnessTable(DeclID WId, SILDefaultWitnessTable *existingWt) {
if (!Linkage) {
LLVM_DEBUG(llvm::dbgs() << "invalid linkage code " << RawLinkage
<< " for SILFunction\n");
MF->fatal();
MF->fatal("invalid linkage code");
}

ProtocolDecl *proto = cast<ProtocolDecl>(MF->getDecl(protoId));
if (proto == nullptr) {
LLVM_DEBUG(llvm::dbgs() << "invalid protocol code " << protoId << "\n");
MF->fatal();
MF->fatal("invalid protocol code");
}

PrettyStackTraceDecl trace("deserializing default witness table for", proto);
Expand All @@ -3682,8 +3672,7 @@ readDefaultWitnessTable(DeclID WId, SILDefaultWitnessTable *existingWt) {
// matches up.
if (wT) {
if (wT->getProtocol() != proto) {
LLVM_DEBUG(llvm::dbgs() << "Protocol mismatch.\n");
MF->fatal();
MF->fatal("Protocol mismatch");
}

// Don't override the linkage of a default witness table with an existing
Expand Down
6 changes: 6 additions & 0 deletions lib/Serialization/ModuleFile.h
Expand Up @@ -352,6 +352,12 @@ class ModuleFile
llvm::inconvertibleErrorCode()));
}

[[noreturn]] void fatal(StringRef msg) const {
fatal(llvm::make_error<llvm::StringError>(
msg,
llvm::inconvertibleErrorCode()));
}

/// Outputs information useful for diagnostics to \p out
void outputDiagnosticInfo(llvm::raw_ostream &os) const;

Expand Down

0 comments on commit 5a2f911

Please sign in to comment.