Skip to content

Commit 87c032f

Browse files
committed
[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
1 parent ef93f7a commit 87c032f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

mlir/lib/IR/Value.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ Value::Value(Operation *op, unsigned resultNo) {
3232

3333
/// Return the type of this value.
3434
Type Value::getType() const {
35+
// Support a null Value so the asmprinter doesn't crash on invalid IR (e.g.
36+
// operations that have dropAllReferences() called on them).
37+
if (!*this)
38+
return Type();
39+
3540
if (BlockArgument arg = dyn_cast<BlockArgument>())
3641
return arg.getType();
3742

0 commit comments

Comments
 (0)