Author: Chris Lattner Date: 2020-12-28T12:37:01-08:00 New Revision: 87c032f7b449cee97751d86739e249738029bf63
URL: https://github.com/llvm/llvm-project/commit/87c032f7b449cee97751d86739e249738029bf63 DIFF: https://github.com/llvm/llvm-project/commit/87c032f7b449cee97751d86739e249738029bf63.diff LOG: [IR] Make Value::getType() work better with invalid IR. The asmprinter would crash when dumping IR objects that had their operands dropped. With this change, we now get this output, which makes op->dump() style debugging more useful. %5 = "firrtl.eq"(<<NULL>>, <<NULL>>) : (<<NULL TYPE>>, <<NULL TYPE>>) -> !firrtl.uint<1> Previously the asmprinter would crash getting the types of the null operands. Differential Revision: https://reviews.llvm.org/D93869 Added: Modified: mlir/lib/IR/Value.cpp Removed: ################################################################################ diff --git a/mlir/lib/IR/Value.cpp b/mlir/lib/IR/Value.cpp index fd7e5b5d64e5..b29641a084a0 100644 --- a/mlir/lib/IR/Value.cpp +++ b/mlir/lib/IR/Value.cpp @@ -32,6 +32,11 @@ Value::Value(Operation *op, unsigned resultNo) { /// Return the type of this value. Type Value::getType() const { + // Support a null Value so the asmprinter doesn't crash on invalid IR (e.g. + // operations that have dropAllReferences() called on them). + if (!*this) + return Type(); + if (BlockArgument arg = dyn_cast<BlockArgument>()) return arg.getType(); _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits