Make the AsmPrinter print "<<NULL TYPE>>" instead of crashing on null types
authorMehdi Amini <joker.eph@gmail.com>
Sun, 5 Apr 2020 03:01:21 +0000 (03:01 +0000)
committerMehdi Amini <joker.eph@gmail.com>
Sun, 5 Apr 2020 18:36:18 +0000 (18:36 +0000)
Even if this indicates in general a problem at call sites, the printer
is used for debugging and avoiding crashing is friendlier for example
when used in diagnostics or other printer.

Differential Revision: https://reviews.llvm.org/D77481

mlir/lib/IR/AsmPrinter.cpp

index bc680cf..987c6b9 100644 (file)
@@ -1490,6 +1490,11 @@ void ModulePrinter::printDenseElementsAttr(DenseElementsAttr attr,
 }
 
 void ModulePrinter::printType(Type type) {
+  if (!type) {
+    os << "<<NULL TYPE>>";
+    return;
+  }
+
   // Check for an alias for this type.
   if (state) {
     StringRef alias = state->getAliasState().getTypeAlias(type);