Skip to content

Commit 9b5155c

Browse files
andrey-golubevOrestChurajoker-eph
authored
[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 <[email protected]> Co-authored-by: Mehdi Amini <[email protected]>
1 parent 2c0a99f commit 9b5155c

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

mlir/tools/mlir-tblgen/OpFormatGen.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ const char *const optionalOperandParserCode = R"(
508508
)";
509509
const char *const operandParserCode = R"(
510510
{0}OperandsLoc = parser.getCurrentLocation();
511-
if (parser.parseOperand({0}RawOperands[0]))
511+
if (parser.parseOperand({0}RawOperand))
512512
return ::mlir::failure();
513513
)";
514514
/// The code snippet used to generate a parser call for a VariadicOfVariadic
@@ -564,11 +564,11 @@ const char *const typeParserCode = R"(
564564
{0} type;
565565
if (parser.parseCustomTypeWithFallback(type))
566566
return ::mlir::failure();
567-
{1}RawTypes[0] = type;
567+
{1}RawType = type;
568568
}
569569
)";
570570
const char *const qualifiedTypeParserCode = R"(
571-
if (parser.parseType({1}RawTypes[0]))
571+
if (parser.parseType({1}RawType))
572572
return ::mlir::failure();
573573
)";
574574

@@ -842,9 +842,9 @@ static void genElementParserStorage(FormatElement *element, const Operator &op,
842842
}
843843
} else {
844844
body << " ::mlir::OpAsmParser::UnresolvedOperand " << name
845-
<< "RawOperands[1];\n"
845+
<< "RawOperand{};\n"
846846
<< " ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> "
847-
<< name << "Operands(" << name << "RawOperands);";
847+
<< name << "Operands(&" << name << "RawOperand, 1);";
848848
}
849849
body << llvm::formatv(" ::llvm::SMLoc {0}OperandsLoc;\n"
850850
" (void){0}OperandsLoc;\n",
@@ -879,10 +879,11 @@ static void genElementParserStorage(FormatElement *element, const Operator &op,
879879
if (lengthKind != ArgumentLengthKind::Single)
880880
body << " ::llvm::SmallVector<::mlir::Type, 1> " << name << "Types;\n";
881881
else
882-
body << llvm::formatv(" ::mlir::Type {0}RawTypes[1];\n", name)
883-
<< llvm::formatv(
884-
" ::llvm::ArrayRef<::mlir::Type> {0}Types({0}RawTypes);\n",
885-
name);
882+
body
883+
<< llvm::formatv(" ::mlir::Type {0}RawType{{};\n", name)
884+
<< llvm::formatv(
885+
" ::llvm::ArrayRef<::mlir::Type> {0}Types(&{0}RawType, 1);\n",
886+
name);
886887
} else if (auto *dir = dyn_cast<FunctionalTypeDirective>(element)) {
887888
ArgumentLengthKind ignored;
888889
body << " ::llvm::ArrayRef<::mlir::Type> "
@@ -910,7 +911,7 @@ static void genCustomParameterParser(FormatElement *param, MethodBody &body) {
910911
else if (lengthKind == ArgumentLengthKind::Optional)
911912
body << llvm::formatv("{0}Operand", name);
912913
else
913-
body << formatv("{0}RawOperands[0]", name);
914+
body << formatv("{0}RawOperand", name);
914915

915916
} else if (auto *region = dyn_cast<RegionVariable>(param)) {
916917
StringRef name = region->getVar()->name;
@@ -939,7 +940,7 @@ static void genCustomParameterParser(FormatElement *param, MethodBody &body) {
939940
else if (lengthKind == ArgumentLengthKind::Optional)
940941
body << llvm::formatv("{0}Type", listName);
941942
else
942-
body << formatv("{0}RawTypes[0]", listName);
943+
body << formatv("{0}RawType", listName);
943944

944945
} else if (auto *string = dyn_cast<StringElement>(param)) {
945946
FmtContext ctx;

0 commit comments

Comments
 (0)