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:
Chris Lattner
2017-12-21 14:29:56 -08:00
parent 8066462cbd
commit 00e961e5f2
2 changed files with 13 additions and 4 deletions

View File

@@ -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};