From 66774771903a0d32e9909e0d40d6f9b1e51b43c0 Mon Sep 17 00:00:00 2001 From: Sean Silva Date: Thu, 26 Mar 2020 14:57:01 -0700 Subject: [PATCH] Verify number of result types in generated builder. Summary: This just bit me and is nasty to debug. Differential Revision: https://reviews.llvm.org/D76888 --- mlir/test/mlir-tblgen/op-result.td | 4 ++++ mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/mlir/test/mlir-tblgen/op-result.td b/mlir/test/mlir-tblgen/op-result.td index 76484c8..c8bdd15 100644 --- a/mlir/test/mlir-tblgen/op-result.td +++ b/mlir/test/mlir-tblgen/op-result.td @@ -38,6 +38,10 @@ def OpC : NS_Op<"three_normal_result_op", []> { // CHECK-NEXT: odsState.addTypes(resultType1) // CHECK-NEXT: odsState.addTypes(z) +// CHECK: void OpC::build(Builder *odsBuilder, OperationState &odsState, ArrayRef resultTypes) { +// CHECK-NEXT: assert(resultTypes.size() == 3u && "mismatched number of results"); +// CHECK-NEXT: odsState.addTypes(resultTypes); + def IntegerTypeAttr : TypeAttrBase<"IntegerType", "Integer type attribute">; def OpD : NS_Op<"type_attr_as_result_type", [FirstAttrDerivedResultType]> { let arguments = (ins I32:$x, IntegerTypeAttr:$attr, F32Attr:$f32); diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp index 47eef13..f262f12 100644 --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -702,6 +702,11 @@ void OpEmitter::genSeparateArgParamBuilder() { } return; case TypeParamKind::Collective: + body << " " + << "assert(resultTypes.size() " + << (op.getNumVariadicResults() == 0 ? "==" : ">=") << " " + << (op.getNumResults() - op.getNumVariadicResults()) + << "u && \"mismatched number of results\");\n"; body << " " << builderOpState << ".addTypes(resultTypes);\n"; return; }; -- 2.7.4