[mlir] fix AsmPrinter after c1eab57673
The change in c1eab57673 fixed the
behavior of `getDiscardableAttrDictionary` for ops that are not using
properties to only return discardable attributes. AsmPrinter was relying
on the wrong behavior when printing such ops in the generic form,
assuming all attributes are discardable.
This commit is contained in:
@@ -3542,8 +3542,9 @@ void OperationPrinter::printGenericOp(Operation *op, bool printOpName) {
|
||||
os << ')';
|
||||
}
|
||||
|
||||
auto attrs = op->getDiscardableAttrs();
|
||||
printOptionalAttrDict(llvm::to_vector(attrs));
|
||||
printOptionalAttrDict(op->getPropertiesStorage()
|
||||
? llvm::to_vector(op->getDiscardableAttrs())
|
||||
: op->getAttrs());
|
||||
|
||||
// Print the type signature of the operation.
|
||||
os << " : ";
|
||||
|
||||
@@ -395,6 +395,12 @@ TEST(OpPropertiesTest, withoutPropertiesDiscardableAttrs) {
|
||||
EXPECT_EQ(op->getAttrs().size(), 2u);
|
||||
EXPECT_TRUE(op->getInherentAttr("inherent_attr") != std::nullopt);
|
||||
EXPECT_TRUE(op->getDiscardableAttr("other_attr") != Attribute());
|
||||
|
||||
std::string output;
|
||||
llvm::raw_string_ostream os(output);
|
||||
op->print(os);
|
||||
EXPECT_TRUE(StringRef(os.str()).contains("inherent_attr = 42"));
|
||||
EXPECT_TRUE(StringRef(os.str()).contains("other_attr = 56"));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user