mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Teach the SILPrinter to be more resilient to null operands.
Previously, when in the debugger and dumping out SIL code, the printer would crash if it encountered a null operand. If you are dumping a basic block, this means that the dump stops at that instruction instead of showing you the whole block. Null operands can happen when you call dropAllReferences() but have yet to delete the instruction. Now the printer is a bit more resilient. We probably don't catch all the cases, but we handle a lot of them, e.g.: %116 = apply <<NULL OPERAND>>(<<NULL OPERAND>>, <<NULL OPERAND>>) : <<NULL CALLEE>> debug_value <<NULL OPERAND>>, let, name "c", argno 1 // id: %120 retain_value <<NULL OPERAND>> // id: %138 Since this is only relevant to invalid IR, this is just a debugging aid, so no testcase.
This commit is contained in:
@@ -104,6 +104,7 @@ public:
|
||||
DEF_COL(ID::SILUndef, RED)
|
||||
DEF_COL(ID::SILBasicBlock, GREEN)
|
||||
DEF_COL(ID::SSAValue, MAGENTA)
|
||||
DEF_COL(ID::Null, YELLOW)
|
||||
}
|
||||
OS.resetColor();
|
||||
OS.changeColor(Color);
|
||||
@@ -128,6 +129,7 @@ void SILPrintContext::ID::print(raw_ostream &OS) {
|
||||
return;
|
||||
case ID::SILBasicBlock: OS << "bb"; break;
|
||||
case ID::SSAValue: OS << '%'; break;
|
||||
case ID::Null: OS << "<<NULL OPERAND>>"; return;
|
||||
}
|
||||
OS << Number;
|
||||
}
|
||||
@@ -509,10 +511,10 @@ public:
|
||||
}
|
||||
|
||||
SILValuePrinterInfo getIDAndType(SILValue V) {
|
||||
return {Ctx.getID(V), V->getType()};
|
||||
return {Ctx.getID(V), V ? V->getType() : SILType()};
|
||||
}
|
||||
SILValuePrinterInfo getIDAndTypeAndOwnership(SILValue V) {
|
||||
return {Ctx.getID(V), V->getType(), V.getOwnershipKind()};
|
||||
return {Ctx.getID(V), V ? V->getType() : SILType(), V.getOwnershipKind()};
|
||||
}
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
@@ -1081,7 +1083,11 @@ public:
|
||||
interleave(AI->getArguments(),
|
||||
[&](const SILValue &arg) { *this << Ctx.getID(arg); },
|
||||
[&] { *this << ", "; });
|
||||
*this << ") : " << AI->getCallee()->getType();
|
||||
*this << ") : ";
|
||||
if (auto callee = AI->getCallee())
|
||||
*this << callee->getType();
|
||||
else
|
||||
*this << "<<NULL CALLEE>>";
|
||||
}
|
||||
|
||||
void visitApplyInst(ApplyInst *AI) {
|
||||
@@ -2975,6 +2981,9 @@ ID SILPrintContext::getID(const SILBasicBlock *Block) {
|
||||
}
|
||||
|
||||
ID SILPrintContext::getID(const SILNode *node) {
|
||||
if (node == nullptr)
|
||||
return {ID::Null, ~0U};
|
||||
|
||||
if (isa<SILUndef>(node))
|
||||
return {ID::SILUndef, 0};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user