[mlir] Check nullity of MixedContainerType and TypedArrayAttrBase

It's valid to create a TypedArrayAttr or MixedContainerType with
    nullptr, e.g.,
      std::vector<mlir::Attribute> 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
This commit is contained in:
Chia-hung Duan 2022-03-08 17:48:08 +00:00
parent e4ab2024a6
commit 60d719b462
2 changed files with 6 additions and 5 deletions

View File

@ -876,9 +876,10 @@ class MixedContainerType<Type etype, Pred containerPred, code elementTypesCall,
And<[
containerPred,
Concat<
"::llvm::all_of(" # elementTypesCall # ", [](Type t) { return ",
"::llvm::all_of(" # elementTypesCall # ", [](Type t) { "
"return t && (",
SubstLeaves<"$_self", "t", etype.predicate>,
"; })"
"); })"
>
]>,
descr # " with any combination of " # etype.summary # " values"> {
@ -1671,9 +1672,9 @@ class TypedArrayAttrBase<Attr element, string summary>: 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;

View File

@ -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<SomeType>()))))
// 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