[Mlir-commits] [mlir] [mlir][OpFormatGen][NFC] Initialize C-style arrays upon creation (PR #85631)
Andrei Golubev
llvmlistbot at llvm.org
Fri Apr 5 04:36:40 PDT 2024
https://github.com/andrey-golubev updated https://github.com/llvm/llvm-project/pull/85631
>From 112b405b3da93f6768a629ed9ad2490346cab0ad 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] Change Raw{Operands,Types} arrays to
objects
Tablegen generates uninitialized arrays of size 1 for raw operands and
types. In the current state this causes static analysis warnings about
"uninitialized fixed-size arrays" as their init is separated from their
declaration. Use uniform-initialized objects instead as it is simpler.
Co-authored-by: Orest Chura <orest.chura at intel.com>
---
mlir/tools/mlir-tblgen/OpFormatGen.cpp | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index 1ffac059f19815..c8e0476d45b9a3 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -508,7 +508,7 @@ const char *const optionalOperandParserCode = R"(
)";
const char *const operandParserCode = R"(
{0}OperandsLoc = parser.getCurrentLocation();
- if (parser.parseOperand({0}RawOperands[0]))
+ if (parser.parseOperand({0}RawOperand))
return ::mlir::failure();
)";
/// The code snippet used to generate a parser call for a VariadicOfVariadic
@@ -564,11 +564,11 @@ const char *const typeParserCode = R"(
{0} type;
if (parser.parseCustomTypeWithFallback(type))
return ::mlir::failure();
- {1}RawTypes[0] = type;
+ {1}RawType = type;
}
)";
const char *const qualifiedTypeParserCode = R"(
- if (parser.parseType({1}RawTypes[0]))
+ if (parser.parseType({1}RawType))
return ::mlir::failure();
)";
@@ -842,9 +842,9 @@ static void genElementParserStorage(FormatElement *element, const Operator &op,
}
} else {
body << " ::mlir::OpAsmParser::UnresolvedOperand " << name
- << "RawOperands[1];\n"
+ << "RawOperand{};\n"
<< " ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> "
- << name << "Operands(" << name << "RawOperands);";
+ << name << "Operands(&" << name << "RawOperand, 1);";
}
body << llvm::formatv(" ::llvm::SMLoc {0}OperandsLoc;\n"
" (void){0}OperandsLoc;\n",
@@ -879,10 +879,11 @@ 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)
- << llvm::formatv(
- " ::llvm::ArrayRef<::mlir::Type> {0}Types({0}RawTypes);\n",
- name);
+ body
+ << llvm::formatv(" ::mlir::Type {0}RawType{{};\n", name)
+ << llvm::formatv(
+ " ::llvm::ArrayRef<::mlir::Type> {0}Types(&{0}RawType, 1);\n",
+ name);
} else if (auto *dir = dyn_cast<FunctionalTypeDirective>(element)) {
ArgumentLengthKind ignored;
body << " ::llvm::ArrayRef<::mlir::Type> "
@@ -910,7 +911,7 @@ static void genCustomParameterParser(FormatElement *param, MethodBody &body) {
else if (lengthKind == ArgumentLengthKind::Optional)
body << llvm::formatv("{0}Operand", name);
else
- body << formatv("{0}RawOperands[0]", name);
+ body << formatv("{0}RawOperand", name);
} else if (auto *region = dyn_cast<RegionVariable>(param)) {
StringRef name = region->getVar()->name;
@@ -939,7 +940,7 @@ static void genCustomParameterParser(FormatElement *param, MethodBody &body) {
else if (lengthKind == ArgumentLengthKind::Optional)
body << llvm::formatv("{0}Type", listName);
else
- body << formatv("{0}RawTypes[0]", listName);
+ body << formatv("{0}RawType", listName);
} else if (auto *string = dyn_cast<StringElement>(param)) {
FmtContext ctx;
More information about the Mlir-commits
mailing list