Make dumping using generic form more robust when IR ill-formed
authorJacques Pienaar <jpienaar@google.com>
Thu, 29 Aug 2019 19:14:02 +0000 (12:14 -0700)
committerA. Unique TensorFlower <gardener@tensorflow.org>
Thu, 29 Aug 2019 19:14:30 +0000 (12:14 -0700)
PiperOrigin-RevId: 266198057

mlir/include/mlir/IR/OpImplementation.h
mlir/lib/IR/AsmPrinter.cpp

index c4e87ce..c97272b 100644 (file)
@@ -116,8 +116,12 @@ public:
   void printFunctionalType(Operation *op) {
     auto &os = getStream();
     os << "(";
-    interleaveComma(op->getNonSuccessorOperands(), os,
-                    [&](Value *operand) { printType(operand->getType()); });
+    interleaveComma(op->getNonSuccessorOperands(), os, [&](Value *operand) {
+      if (operand)
+        printType(operand->getType());
+      else
+        os << "<<NULL>";
+    });
     os << ") -> ";
     if (op->getNumResults() == 1 &&
         !op->getResult(0)->getType().isa<FunctionType>()) {
index 06c5eac..794060d 100644 (file)
@@ -1511,6 +1511,11 @@ void OperationPrinter::print(Operation *op) {
 
 void OperationPrinter::printValueIDImpl(Value *value, bool printResultNo,
                                         raw_ostream &stream) const {
+  if (!value) {
+    stream << "<<NULL>>";
+    return;
+  }
+
   int resultNo = -1;
   auto lookupValue = value;