static void build(Builder *builder, OperationState *result, StringRef name,
FunctionType type, ArrayRef<NamedAttribute> attrs);
- /// Parsing/Printing methods.
+ /// Operation hooks.
static ParseResult parse(OpAsmParser *parser, OperationState *result);
void print(OpAsmPrinter *p);
+ LogicalResult verify();
/// Returns the name of this function.
StringRef getName() { return getAttrOfType<StringAttr>("name").getValue(); }
*p << '\n';
}
+LogicalResult FuncOp::verify() {
+ // If this function is external there is nothing to do.
+ if (isExternal())
+ return success();
+
+ // Verify that the argument list of the function and the arg list of the entry
+ // block line up.
+ Block &entryBlock = front();
+ auto fnInputTypes = getType().getInputs();
+ if (fnInputTypes.size() != entryBlock.getNumArguments())
+ return emitOpError("entry block must have ")
+ << fnInputTypes.size() << " arguments to match function signature";
+
+ for (unsigned i = 0, e = entryBlock.getNumArguments(); i != e; ++i)
+ if (fnInputTypes[i] != entryBlock.getArgument(i)->getType())
+ return emitOpError("type of entry block argument #")
+ << i << '(' << entryBlock.getArgument(i)->getType()
+ << ") must match the type of the corresponding argument in "
+ << "function signature(" << fnInputTypes[i] << ')';
+
+ return success();
+}
+
//===----------------------------------------------------------------------===//
// Function Argument Attribute.
//===----------------------------------------------------------------------===//
func @mixed_named_arguments(%a : i32)
return
}
+
+// -----
+
+func @func_op() {
+ // expected-error@+1 {{entry block must have 1 arguments to match function signature}}
+ func @mixed_named_arguments(f32) {
+ ^entry:
+ return
+ }
+ return
+}
+
+// -----
+
+func @func_op() {
+ // expected-error@+1 {{type of entry block argument #0('i32') must match the type of the corresponding argument in function signature('f32')}}
+ func @mixed_named_arguments(f32) {
+ ^entry(%arg : i32):
+ return
+ }
+ return
+}