Skip to content

Commit 5a2f911

Browse files
authored
Merge pull request swiftlang#40729 from xymus/sil-deser-prints
[Serialization/SIL] Print error messages in the pretty stacktrace
2 parents cc12c4e + d270593 commit 5a2f911

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

lib/Serialization/DeserializeSIL.cpp

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,7 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
506506
return maybeEntry.takeError();
507507
llvm::BitstreamEntry entry = maybeEntry.get();
508508
if (entry.Kind == llvm::BitstreamEntry::Error) {
509-
LLVM_DEBUG(llvm::dbgs() << "Cursor advance error in readSILFunction.\n");
510-
MF->fatal();
509+
MF->fatal("Cursor advance error in readSILFunction");
511510
}
512511

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

543542
if (funcTyID == 0) {
544-
LLVM_DEBUG(llvm::dbgs() << "SILFunction typeID is 0.\n");
545-
MF->fatal();
543+
MF->fatal("SILFunction typeID is 0");
546544
}
547545
auto astType = MF->getTypeChecked(funcTyID);
548546
if (!astType) {
@@ -555,8 +553,7 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
555553
}
556554
auto ty = getSILType(astType.get(), SILValueCategory::Object, nullptr);
557555
if (!ty.is<SILFunctionType>()) {
558-
LLVM_DEBUG(llvm::dbgs() << "not a function type for SILFunction\n");
559-
MF->fatal();
556+
MF->fatal("not a function type for SILFunction");
560557
}
561558

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

581578
ValueDecl *clangNodeOwner = nullptr;
582579
if (clangNodeOwnerID != 0) {
583580
clangNodeOwner = dyn_cast_or_null<ValueDecl>(MF->getDecl(clangNodeOwnerID));
584581
if (!clangNodeOwner) {
585-
LLVM_DEBUG(llvm::dbgs() << "invalid clang node owner for SILFunction\n");
586-
MF->fatal();
582+
MF->fatal("invalid clang node owner for SILFunction");
587583
}
588584
}
589585

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

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

644639
if (fn->isDynamicallyReplaceable() != isDynamic) {
645-
LLVM_DEBUG(llvm::dbgs() << "SILFunction type mismatch.\n");
646-
MF->fatal();
640+
MF->fatal("SILFunction type mismatch");
647641
}
648642

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

841835
// Handle a SILInstruction record.
842836
if (readSILInstruction(fn, Builder, kind, scratch)) {
843-
LLVM_DEBUG(llvm::dbgs() << "readSILInstruction returns error.\n");
844-
MF->fatal();
837+
MF->fatal("readSILInstruction returns error");
845838
}
846839
}
847840

@@ -2936,8 +2929,7 @@ bool SILDeserializer::hasSILFunction(StringRef Name,
29362929
MF->fatal(maybeEntry.takeError());
29372930
llvm::BitstreamEntry entry = maybeEntry.get();
29382931
if (entry.Kind == llvm::BitstreamEntry::Error) {
2939-
LLVM_DEBUG(llvm::dbgs() << "Cursor advance error in hasSILFunction.\n");
2940-
MF->fatal();
2932+
MF->fatal("Cursor advance error in hasSILFunction");
29412933
}
29422934

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

31203111
// Fetch the next record.
@@ -3496,7 +3487,7 @@ llvm::Expected<SILWitnessTable *>
34963487
if (!Linkage) {
34973488
LLVM_DEBUG(llvm::dbgs() << "invalid linkage code " << RawLinkage
34983489
<< " for SILFunction\n");
3499-
MF->fatal();
3490+
MF->fatal("invalid linkage code");
35003491
}
35013492

35023493
// Deserialize Conformance.
@@ -3518,8 +3509,7 @@ llvm::Expected<SILWitnessTable *>
35183509
// up.
35193510
if (wT) {
35203511
if (wT->getConformance() != theConformance) {
3521-
LLVM_DEBUG(llvm::dbgs() << "Conformance mismatch.\n");
3522-
MF->fatal();
3512+
MF->fatal("Conformance mismatch");
35233513
}
35243514

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

36693659
ProtocolDecl *proto = cast<ProtocolDecl>(MF->getDecl(protoId));
36703660
if (proto == nullptr) {
36713661
LLVM_DEBUG(llvm::dbgs() << "invalid protocol code " << protoId << "\n");
3672-
MF->fatal();
3662+
MF->fatal("invalid protocol code");
36733663
}
36743664

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

36893678
// Don't override the linkage of a default witness table with an existing

lib/Serialization/ModuleFile.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,12 @@ class ModuleFile
352352
llvm::inconvertibleErrorCode()));
353353
}
354354

355+
[[noreturn]] void fatal(StringRef msg) const {
356+
fatal(llvm::make_error<llvm::StringError>(
357+
msg,
358+
llvm::inconvertibleErrorCode()));
359+
}
360+
355361
/// Outputs information useful for diagnostics to \p out
356362
void outputDiagnosticInfo(llvm::raw_ostream &os) const;
357363

0 commit comments

Comments
 (0)