[Mlir-commits] [mlir] 9b5155c - [mlir][OpFormatGen][NFC] Change Raw{Operands, Types} arrays to objects (#85631)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Apr 5 04:49:36 PDT 2024
Author: Andrei Golubev
Date: 2024-04-05T13:49:32+02:00
New Revision: 9b5155c93616563165c9d8da5f15aa1f1260d2d2
URL: https://github.com/llvm/llvm-project/commit/9b5155c93616563165c9d8da5f15aa1f1260d2d2
DIFF: https://github.com/llvm/llvm-project/commit/9b5155c93616563165c9d8da5f15aa1f1260d2d2.diff
LOG: [mlir][OpFormatGen][NFC] Change Raw{Operands,Types} arrays to objects (#85631)
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. Since these are single-entry array, we can just use a plain
variable instead of an array here.
Co-authored-by: Orest Chura <orest.chura at intel.com>
Co-authored-by: Mehdi Amini <joker.eph at gmail.com>
Added:
Modified:
mlir/tools/mlir-tblgen/OpFormatGen.cpp
Removed:
################################################################################
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