[llvm] [mlir] [MLIR][ADT] Fix uninitialized scalar and array-vs-singleton patterns flagged by Coverity in generated code (PR #215217)

via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 10 01:36:52 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-adt

Author: Sylvestre Ledru (sylvestre)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/215217.diff


2 Files Affected:

- (modified) llvm/include/llvm/ADT/STLFunctionalExtras.h (+1-1) 
- (modified) mlir/tools/mlir-tblgen/OpFormatGen.cpp (+10-11) 


``````````diff
diff --git a/llvm/include/llvm/ADT/STLFunctionalExtras.h b/llvm/include/llvm/ADT/STLFunctionalExtras.h
index a4d50dc3648be..f6dbd8b1840ac 100644
--- a/llvm/include/llvm/ADT/STLFunctionalExtras.h
+++ b/llvm/include/llvm/ADT/STLFunctionalExtras.h
@@ -39,7 +39,7 @@ template<typename Fn> class function_ref;
 template <typename Ret, typename... Params>
 class LLVM_GSL_POINTER function_ref<Ret(Params...)> {
   Ret (*callback)(intptr_t callable, Params ...params) = nullptr;
-  intptr_t callable;
+  intptr_t callable = 0;
 
   template<typename Callable>
   static Ret callback_fn(intptr_t callable, Params ...params) {
diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index 2ae276a62e939..3732ed9d5fbe4 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -590,7 +590,7 @@ const char *const optionalOperandParserCode = R"(
 )";
 const char *const operandParserCode = R"(
   {0}OperandsLoc = parser.getCurrentLocation();
-  if (parser.parseOperand({0}RawOperand))
+  if (parser.parseOperand({0}RawOperands[0]))
     return ::mlir::failure();
 )";
 /// The code snippet used to generate a parser call for a VariadicOfVariadic
@@ -646,11 +646,11 @@ const char *const typeParserCode = R"(
     {0} type;
     if (parser.parseCustomTypeWithFallback(type))
       return ::mlir::failure();
-    {1}RawType = type;
+    {1}RawTypes[0] = type;
   }
 )";
 const char *const qualifiedTypeParserCode = R"(
-  if (parser.parseType({1}RawType))
+  if (parser.parseType({1}RawTypes[0]))
     return ::mlir::failure();
 )";
 
@@ -924,9 +924,9 @@ static void genElementParserStorage(FormatElement *element, const Operator &op,
       }
     } else {
       body << "  ::mlir::OpAsmParser::UnresolvedOperand " << name
-           << "RawOperand{};\n"
+           << "RawOperands[1] = {};\n"
            << "  ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> "
-           << name << "Operands(&" << name << "RawOperand, 1);";
+           << name << "Operands(" << name << "RawOperands);";
     }
     body << formatv("  ::llvm::SMLoc {0}OperandsLoc;\n"
                     "  (void){0}OperandsLoc;\n",
@@ -962,10 +962,9 @@ static void genElementParserStorage(FormatElement *element, const Operator &op,
       body << "  ::llvm::SmallVector<::mlir::Type, 1> " << name << "Types;\n";
     else
       body
-          << formatv("  ::mlir::Type {0}RawType{{};\n", name)
-          << formatv(
-                 "  ::llvm::ArrayRef<::mlir::Type> {0}Types(&{0}RawType, 1);\n",
-                 name);
+          << formatv("  ::mlir::Type {0}RawTypes[1] = {{};\n", name)
+          << formatv("  ::llvm::ArrayRef<::mlir::Type> {0}Types({0}RawTypes);\n",
+                     name);
   } else if (auto *dir = dyn_cast<FunctionalTypeDirective>(element)) {
     ArgumentLengthKind ignored;
     body << "  ::llvm::ArrayRef<::mlir::Type> "
@@ -994,7 +993,7 @@ static void genCustomParameterParser(FormatElement *param, MethodBody &body,
     else if (lengthKind == ArgumentLengthKind::Optional)
       body << formatv("{0}Operand", name);
     else
-      body << formatv("{0}RawOperand", name);
+      body << formatv("{0}RawOperands[0]", name);
 
   } else if (auto *region = dyn_cast<RegionVariable>(param)) {
     StringRef name = region->getVar()->name;
@@ -1023,7 +1022,7 @@ static void genCustomParameterParser(FormatElement *param, MethodBody &body,
     else if (lengthKind == ArgumentLengthKind::Optional)
       body << formatv("{0}Type", listName);
     else
-      body << formatv("{0}RawType", listName);
+      body << formatv("{0}RawTypes[0]", listName);
 
   } else if (auto *string = dyn_cast<StringElement>(param)) {
     FmtContext ctx;

``````````

</details>


https://github.com/llvm/llvm-project/pull/215217


More information about the llvm-commits mailing list