diff --git a/mlir/test/mlir-tblgen/op-attribute.td b/mlir/test/mlir-tblgen/op-attribute.td --- a/mlir/test/mlir-tblgen/op-attribute.td +++ b/mlir/test/mlir-tblgen/op-attribute.td @@ -278,6 +278,30 @@ let arguments = (ins F32Attr:$attr, F32:$operand, F32Attr:$otherAttr, F32:$otherArg); } +def OpWithDefaultAndRegion : NS_Op<"default_with_region", []> { + let arguments = (ins + DefaultValuedAttr:$dv_bool_attr + ); + let regions = (region VariadicRegion:$region); +} + +// We should not have a default attribute in this case. + +// DECL-LABEL: OpWithDefaultAndRegion declarations +// DECL: static void build({{.*}}, bool dv_bool_attr, unsigned regionCount) + +def OpWithDefaultAndSuccessor : NS_Op<"default_with_succ", []> { + let arguments = (ins + DefaultValuedAttr:$dv_bool_attr + ); + let successors = (successor VariadicSuccessor:$succ); +} + +// We should not have a default attribute in this case. + +// DECL-LABEL: OpWithDefaultAndSuccessor declarations +// DECL: static void build({{.*}}, bool dv_bool_attr, ::mlir::BlockRange succ) + // DEF-LABEL: MixOperandsAndAttrs definitions // DEF-DAG: ::mlir::Value MixOperandsAndAttrs::operand() // DEF-DAG: ::mlir::Value MixOperandsAndAttrs::otherArg() diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -1512,7 +1512,10 @@ // Add parameters for all arguments (operands and attributes). int defaultValuedAttrStartIndex = op.getNumArgs(); - if (attrParamKind == AttrParamKind::UnwrappedValue) { + // Successors and variadic regions go at the end of the parameter list, so no + // default arguments are possible. + bool hasTrailingParams = op.getNumSuccessors() || op.getNumVariadicRegions(); + if (attrParamKind == AttrParamKind::UnwrappedValue && !hasTrailingParams) { // Calculate the start index from which we can attach default values in the // builder declaration. for (int i = op.getNumArgs() - 1; i >= 0; --i) {