diff --git a/mlir/test/lib/Dialect/Test/TestOpsSyntax.td b/mlir/test/lib/Dialect/Test/TestOpsSyntax.td index 795b9da955632c..c988d1f0ec871a 100644 --- a/mlir/test/lib/Dialect/Test/TestOpsSyntax.td +++ b/mlir/test/lib/Dialect/Test/TestOpsSyntax.td @@ -431,6 +431,13 @@ def FormatOptionalWithElse : TEST_Op<"format_optional_else"> { let assemblyFormat = "(`then` $isFirstBranchPresent^):(`else`)? attr-dict"; } +def FormatOptionalPropDict : TEST_Op<"format_optional_prop_dict"> { + let arguments = (ins + OptionalProperty:$a, + DefaultValuedProperty:$b); + let assemblyFormat = "prop-dict attr-dict"; +} + def FormatCompoundAttr : TEST_Op<"format_compound_attr"> { let arguments = (ins CompoundAttrA:$compound); let assemblyFormat = "$compound attr-dict-with-keyword"; diff --git a/mlir/test/mlir-tblgen/op-format.mlir b/mlir/test/mlir-tblgen/op-format.mlir index 03288ae8bd3d77..08b0c52413a757 100644 --- a/mlir/test/mlir-tblgen/op-format.mlir +++ b/mlir/test/mlir-tblgen/op-format.mlir @@ -276,6 +276,29 @@ test.format_optional_else then // CHECK: test.format_optional_else else test.format_optional_else else +//===----------------------------------------------------------------------===// +// Default-valued properties (ex. optional) elided in property dictionary +// TODO: elisions generate extra spaces +//===----------------------------------------------------------------------===// + +// CHECK: test.format_optional_prop_dict {{$}} +test.format_optional_prop_dict + +// CHECK: test.format_optional_prop_dict {{$}} +test.format_optional_prop_dict <{a = [], b = 1 : i32}> + +// CHECK: test.format_optional_prop_dict {{$}} +test.format_optional_prop_dict <{}> + +// CHECK: test.format_optional_prop_dict < {a = ["foo"]}> +test.format_optional_prop_dict <{a = ["foo"]}> + +// CHECK: test.format_optional_prop_dict < {b = 2 : i32}> +test.format_optional_prop_dict <{b = 2 : i32}> + +// CHECK: test.format_optional_prop_dict <{a = ["foo"], b = 2 : i32}> +test.format_optional_prop_dict <{a = ["foo"], b = 2 : i32}> + //===----------------------------------------------------------------------===// // Format a custom attribute //===----------------------------------------------------------------------===// diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp index 097a578cb2025e..1f8d8992f898ab 100644 --- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp +++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp @@ -1309,7 +1309,7 @@ if (!attr && {2}) {{ "Properties."; return ::mlir::failure(); } -if (::mlir::failed(setFromAttr(prop.{1}, attr, emitError))) +if (attr && ::mlir::failed(setFromAttr(prop.{1}, attr, emitError))) return ::mlir::failure(); )decl";