From 60d719b462a136a75610bf1d1c9f4e043d394eea Mon Sep 17 00:00:00 2001 From: Chia-hung Duan Date: Tue, 8 Mar 2022 17:48:08 +0000 Subject: [PATCH] [mlir] Check nullity of MixedContainerType and TypedArrayAttrBase It's valid to create a TypedArrayAttr or MixedContainerType with nullptr, e.g., std::vector attrs = {mlir::StringAttr()}; builder.createArrayAttr(attrs); The predicate didn't check if it's a nullptr and it ended up a crash in the attribute static verifier. We always check if an attribute is null so it's better to align the check for these two container type attr. Reviewed By: rdzhabarov Differential Revision: https://reviews.llvm.org/D121178 --- mlir/include/mlir/IR/OpBase.td | 9 +++++---- mlir/test/mlir-tblgen/op-attribute.td | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td index fa40ca7819c0..8a72766d55f4 100644 --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -876,9 +876,10 @@ class MixedContainerType, - "; })" + "); })" > ]>, descr # " with any combination of " # etype.summary # " values"> { @@ -1671,9 +1672,9 @@ class TypedArrayAttrBase: ArrayAttrBase< CPred<"$_self.isa<::mlir::ArrayAttr>()">, // Guarantee all elements satisfy the constraints from `element` Concat<"::llvm::all_of($_self.cast<::mlir::ArrayAttr>(), " - "[&](::mlir::Attribute attr) { return ", + "[&](::mlir::Attribute attr) { return attr && (", SubstLeaves<"$_self", "attr", element.predicate>, - "; })">]>, + "); })">]>, summary> { Attr elementAttr = element; diff --git a/mlir/test/mlir-tblgen/op-attribute.td b/mlir/test/mlir-tblgen/op-attribute.td index f4d32aeb4c65..241c8c6929b5 100644 --- a/mlir/test/mlir-tblgen/op-attribute.td +++ b/mlir/test/mlir-tblgen/op-attribute.td @@ -282,7 +282,7 @@ def BOp : NS_Op<"b_op", []> { // DEF: if (tblgen_function_attr && !((tblgen_function_attr.isa<::mlir::FlatSymbolRefAttr>()))) // DEF: if (tblgen_some_type_attr && !(((tblgen_some_type_attr.isa<::mlir::TypeAttr>())) && ((tblgen_some_type_attr.cast<::mlir::TypeAttr>().getValue().isa())))) // DEF: if (tblgen_array_attr && !((tblgen_array_attr.isa<::mlir::ArrayAttr>()))) -// DEF: if (tblgen_some_attr_array && !(((tblgen_some_attr_array.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_some_attr_array.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return (some-condition); })))) +// DEF: if (tblgen_some_attr_array && !(((tblgen_some_attr_array.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_some_attr_array.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((some-condition)); })))) // DEF: if (tblgen_type_attr && !(((tblgen_type_attr.isa<::mlir::TypeAttr>())) && ((tblgen_type_attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>())))) // Test common attribute kind getters' return types