[Mlir-commits] [mlir] [mlir][ODS] Suppress generated ArrayRef Coverity warning (PR #220601)
Mehdi Amini
llvmlistbot at llvm.org
Wed Sep 2 06:58:12 PDT 2026
https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/220601
Declarative parsers represent fixed-length operands and types as ArrayRefs to scalar storage. Coverity loses the explicit length at resolveOperands calls and reports ARRAY_VS_SINGLETON for the generated code.
Emit the checker-specific suppression at those generated call sites and test that it remains in the generated parser.
Found by Coverity.
Assisted-by: Codex
>From a033946cc2152b8e692cc2d7338f663aa5cbbfef Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Wed, 2 Sep 2026 06:49:59 -0700
Subject: [PATCH] [mlir][tblgen] Suppress generated ArrayRef Coverity warning
Declarative parsers represent fixed-length operands and types as ArrayRefs to
scalar storage. Coverity loses the explicit length at resolveOperands calls
and reports ARRAY_VS_SINGLETON for the generated code.
Emit the checker-specific suppression at those generated call sites and test
that it remains in the generated parser.
Found by Coverity.
Assisted-by: Codex
---
mlir/test/mlir-tblgen/op-format.td | 3 +++
mlir/tools/mlir-tblgen/OpFormatGen.cpp | 11 +++++++++++
2 files changed, 14 insertions(+)
diff --git a/mlir/test/mlir-tblgen/op-format.td b/mlir/test/mlir-tblgen/op-format.td
index baded36fa7b3e..31e1ef2297688 100644
--- a/mlir/test/mlir-tblgen/op-format.td
+++ b/mlir/test/mlir-tblgen/op-format.td
@@ -27,6 +27,9 @@ class TestStrictPropertiesFormat_Op<string fmt, list<Trait> traits = []>
// custom
//===----------------------------------------------------------------------===//
+// CHECK-LABEL: AttrDictContextOperand::parse
+// CHECK: // coverity[ARRAY_VS_SINGLETON]
+// CHECK-NEXT: if (parser.resolveOperands(
// CHECK-LABEL: AttrDictContextOperand::print
// CHECK: _odsPrinter.printOptionalAttrDict(_odsAttrs.getDictionary((*this)->getContext()).getValue(), elidedAttrs);
def AttrDictContextOperand : TestFormat_Op<[{
diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index 29982d486b5c3..e802bd35e914c 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -2272,6 +2272,13 @@ void OperationFormat::genParserTypeResolution(Operator &op, MethodBody &body) {
void OperationFormat::genParserOperandTypeResolution(
Operator &op, MethodBody &body,
function_ref<void(TypeResolution &, StringRef)> emitTypeResolver) {
+ // Fixed-length parser variables are represented as ArrayRefs to scalar
+ // storage. Coverity does not track the explicit length and reports the
+ // resolveOperands calls as ARRAY_VS_SINGLETON.
+ auto emitArrayVsSingletonSuppression = [&] {
+ body << " // coverity[ARRAY_VS_SINGLETON]\n";
+ };
+
// Early exit if there are no operands.
if (op.getNumOperands() == 0)
return;
@@ -2281,6 +2288,7 @@ void OperationFormat::genParserOperandTypeResolution(
if (allOperandTypes) {
// If `operands` was specified, use the full operand list directly.
if (allOperands) {
+ emitArrayVsSingletonSuppression();
body << " if (parser.resolveOperands(allOperands, allOperandTypes, "
"allOperandLoc, result.operands))\n"
" return ::mlir::failure();\n";
@@ -2289,6 +2297,7 @@ void OperationFormat::genParserOperandTypeResolution(
// Otherwise, use llvm::concat to merge the disjoint operand lists together.
// llvm::concat does not allow the case of a single range, so guard it here.
+ emitArrayVsSingletonSuppression();
body << " if (parser.resolveOperands(";
if (op.getNumOperands() > 1) {
body << "::llvm::concat<const ::mlir::OpAsmParser::UnresolvedOperand>(";
@@ -2306,6 +2315,7 @@ void OperationFormat::genParserOperandTypeResolution(
// Handle the case where all operands are grouped together with "operands".
if (allOperands) {
+ emitArrayVsSingletonSuppression();
body << " if (parser.resolveOperands(allOperands, ";
// Group all of the operand types together to perform the resolution all at
@@ -2341,6 +2351,7 @@ void OperationFormat::genParserOperandTypeResolution(
operand.isOptional() && !operandType.isDirectlyParsed();
if (guardOptionalOperand)
body << " if (!" << operand.name << "Operands.empty()) {\n";
+ emitArrayVsSingletonSuppression();
body << " if (parser.resolveOperands(" << operand.name << "Operands, ";
// Resolve the type of this operand.
More information about the Mlir-commits
mailing list