From 6132720b3a99d30a75608874d749cf03251d8969 Mon Sep 17 00:00:00 2001 From: John Demme Date: Tue, 19 Sep 2023 23:52:03 +0000 Subject: [PATCH] [MSFT] Implicit InnerRefAttr printer crashes on null attributes Printers should *never* crash since they are used when printing asm which doesn't verify. --- lib/Dialect/MSFT/MSFTOps.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Dialect/MSFT/MSFTOps.cpp b/lib/Dialect/MSFT/MSFTOps.cpp index d6a09b938b29..ce7cdc997593 100644 --- a/lib/Dialect/MSFT/MSFTOps.cpp +++ b/lib/Dialect/MSFT/MSFTOps.cpp @@ -170,8 +170,14 @@ static ParseResult parseImplicitInnerRef(OpAsmParser &p, } void printImplicitInnerRef(OpAsmPrinter &p, Operation *, hw::InnerRefAttr innerRef) { - p << SymbolRefAttr::get(innerRef.getModule(), - {FlatSymbolRefAttr::get(innerRef.getName())}); + MLIRContext *ctxt = innerRef.getContext(); + StringRef innerRefNameStr, moduleStr; + if (innerRef.getName()) + innerRefNameStr = innerRef.getName().getValue(); + if (innerRef.getModule()) + moduleStr = innerRef.getModule().getValue(); + p << SymbolRefAttr::get(ctxt, moduleStr, + {FlatSymbolRefAttr::get(ctxt, innerRefNameStr)}); } /// Parse an parameter list if present. Same format as HW dialect.