From 2ed19c40a29db9b374021c69ebae82b125ecf983 Mon Sep 17 00:00:00 2001 From: Mariusz Sikora Date: Sun, 2 Feb 2025 12:03:18 -0500 Subject: [PATCH] [TableGen] Fix OperandMap table size - add missing value for OPERAND_LAST type. If function 'getNamedOperandIdx' is called with NamedIdx=OPERAND_LAST then we are accessing first element of next row in 2dim table. - in most cases this will work unnoticed because 2dim OperandMap is sparse with most elements set to '-1'. --- llvm/utils/TableGen/InstrInfoEmitter.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/llvm/utils/TableGen/InstrInfoEmitter.cpp b/llvm/utils/TableGen/InstrInfoEmitter.cpp index 97c00ad492419..ecf30c95f4b76 100644 --- a/llvm/utils/TableGen/InstrInfoEmitter.cpp +++ b/llvm/utils/TableGen/InstrInfoEmitter.cpp @@ -300,8 +300,8 @@ void InstrInfoEmitter::emitOperandNameMappings( assert(MaxOperandNo <= INT16_MAX && "Too many operands for the operand name -> index table"); StringRef Type = MaxOperandNo <= INT8_MAX ? "int8_t" : "int16_t"; - OS << " static constexpr " << Type << " OperandMap[][" << NumOperandNames - << "] = {\n"; + OS << " static constexpr " << Type << " OperandMap[][" + << NumOperandNames + 1 << "] = {\n"; for (const auto &Entry : OperandMap) { const std::map &OpList = Entry.first; @@ -311,7 +311,8 @@ void InstrInfoEmitter::emitOperandNameMappings( auto Iter = OpList.find(ID); OS << (Iter != OpList.end() ? (int)Iter->second : -1) << ", "; } - OS << "},\n"; + // value for OPERAND_LAST + OS << "-1 },\n"; } OS << " };\n";