diff --git a/lib/TableGen/Operations.cpp b/lib/TableGen/Operations.cpp index a7d09af..5463bec 100644 --- a/lib/TableGen/Operations.cpp +++ b/lib/TableGen/Operations.cpp @@ -463,9 +463,17 @@ void Operation::emitVerifierMethod(llvm::raw_ostream &out, fmt.withContext(symbols.chooseName("context")); fmt.addSubst("_errs", symbols.chooseName("errs")); + bool emitArgCountVerifier = true; if (m_hasVariadicArgument) { - fmt.addSubst("_comparator", "<"); - fmt.addSubst("_at_least", "at least "); + if (getNumFullArguments() == 0) { + // If the only argument in an operation is a variadic argument list, + // getNumFullArguments() will return zero. Thus, prevent us from emitting + // arg_size() < 0 verifier checks. + emitArgCountVerifier = false; + } else { + fmt.addSubst("_comparator", "<"); + fmt.addSubst("_at_least", "at least "); + } } else { fmt.addSubst("_comparator", "!="); fmt.addSubst("_at_least", ""); @@ -477,14 +485,19 @@ void Operation::emitVerifierMethod(llvm::raw_ostream &out, (void)$_context; using ::llvm_dialects::printable; + )", + &fmt); + if (emitArgCountVerifier) { + out << tgfmt(R"( if (arg_size() $_comparator $0) { $_errs << " wrong number of arguments: " << arg_size() << ", expected $_at_least$0\n"; return false; } )", - &fmt, getNumFullArguments()); + &fmt, getNumFullArguments()); + } Assignment assignment; Evaluator eval(symbols, assignment, m_system, out, fmt); diff --git a/test/example/generated/ExampleDialect.cpp.inc b/test/example/generated/ExampleDialect.cpp.inc index 138817b..d04c044 100644 --- a/test/example/generated/ExampleDialect.cpp.inc +++ b/test/example/generated/ExampleDialect.cpp.inc @@ -368,7 +368,7 @@ rhs, (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 3) { errs << " wrong number of arguments: " << arg_size() << ", expected 3\n"; @@ -487,7 +487,7 @@ rhs (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 2) { errs << " wrong number of arguments: " << arg_size() << ", expected 2\n"; @@ -582,7 +582,7 @@ index (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 2) { errs << " wrong number of arguments: " << arg_size() << ", expected 2\n"; @@ -685,7 +685,7 @@ source (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 1) { errs << " wrong number of arguments: " << arg_size() << ", expected 1\n"; @@ -849,7 +849,7 @@ source (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 0) { errs << " wrong number of arguments: " << arg_size() << ", expected 0\n"; @@ -917,7 +917,7 @@ source (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 1) { errs << " wrong number of arguments: " << arg_size() << ", expected 1\n"; @@ -1015,7 +1015,7 @@ source (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 1) { errs << " wrong number of arguments: " << arg_size() << ", expected 1\n"; @@ -1184,7 +1184,7 @@ index (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 3) { errs << " wrong number of arguments: " << arg_size() << ", expected 3\n"; @@ -1302,7 +1302,7 @@ instName_0 (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 2) { errs << " wrong number of arguments: " << arg_size() << ", expected 2\n"; @@ -1385,7 +1385,7 @@ instName (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 1) { errs << " wrong number of arguments: " << arg_size() << ", expected 1\n"; @@ -1461,12 +1461,6 @@ instName (void)context; using ::llvm_dialects::printable; - - if (arg_size() < 0) { - errs << " wrong number of arguments: " << arg_size() - << ", expected at least 0\n"; - return false; - } ::llvm::Type * const resultType = getResult()->getType(); (void)resultType; @@ -1531,7 +1525,7 @@ instName (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 0) { errs << " wrong number of arguments: " << arg_size() << ", expected 0\n"; @@ -1588,7 +1582,7 @@ instName (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 0) { errs << " wrong number of arguments: " << arg_size() << ", expected 0\n"; @@ -1645,7 +1639,7 @@ data (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 1) { errs << " wrong number of arguments: " << arg_size() << ", expected 1\n"; @@ -1708,7 +1702,7 @@ data (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 1) { errs << " wrong number of arguments: " << arg_size() << ", expected 1\n"; @@ -1787,7 +1781,7 @@ initial (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 3) { errs << " wrong number of arguments: " << arg_size() << ", expected 3\n"; @@ -1879,7 +1873,7 @@ initial (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 3) { errs << " wrong number of arguments: " << arg_size() << ", expected 3\n"; @@ -1971,7 +1965,7 @@ initial (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 3) { errs << " wrong number of arguments: " << arg_size() << ", expected 3\n"; @@ -2058,7 +2052,7 @@ data (void)context; using ::llvm_dialects::printable; - + if (arg_size() != 1) { errs << " wrong number of arguments: " << arg_size() << ", expected 1\n"; @@ -2123,7 +2117,7 @@ data (void)context; using ::llvm_dialects::printable; - + if (arg_size() < 1) { errs << " wrong number of arguments: " << arg_size() << ", expected at least 1\n";