[Mlir-commits] [mlir] [mlir][OpFormatGen][NFC] Initialize C-style arrays upon creation (PR #85631)

Andrei Golubev llvmlistbot at llvm.org
Mon Mar 18 04:29:53 PDT 2024


https://github.com/andrey-golubev created https://github.com/llvm/llvm-project/pull/85631

Static analysis would warn about uninitialized fixed-size arrays in tablegen-generated code.

>From 641c0a46b5fb549f61b0281046b01decf9fb8c1d Mon Sep 17 00:00:00 2001
From: "Golubev, Andrey" <andrey.golubev at intel.com>
Date: Mon, 18 Mar 2024 11:14:56 +0000
Subject: [PATCH] [mlir][OpFormatGen][NFC] Initialize C-style arrays upon
 creation

Static analysis would warn about uninitialized fixed-size arrays in
tablegen-generated code.

Co-authored-by: Orest Chura <orest.chura at intel.com>
---
 mlir/tools/mlir-tblgen/OpFormatGen.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index 1ffac059f19815..4c96b72f305808 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -842,7 +842,7 @@ static void genElementParserStorage(FormatElement *element, const Operator &op,
       }
     } else {
       body << "  ::mlir::OpAsmParser::UnresolvedOperand " << name
-           << "RawOperands[1];\n"
+           << "RawOperands[1] = {};\n"
            << "  ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> "
            << name << "Operands(" << name << "RawOperands);";
     }
@@ -879,7 +879,7 @@ static void genElementParserStorage(FormatElement *element, const Operator &op,
     if (lengthKind != ArgumentLengthKind::Single)
       body << "  ::llvm::SmallVector<::mlir::Type, 1> " << name << "Types;\n";
     else
-      body << llvm::formatv("  ::mlir::Type {0}RawTypes[1];\n", name)
+      body << llvm::formatv("  ::mlir::Type {0}RawTypes[1] = {{};\n", name)
            << llvm::formatv(
                   "  ::llvm::ArrayRef<::mlir::Type> {0}Types({0}RawTypes);\n",
                   name);



More information about the Mlir-commits mailing list