Skip to content

Commit 2ed19c4

Browse files
[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'.
1 parent 689ef5f commit 2ed19c4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

llvm/utils/TableGen/InstrInfoEmitter.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ void InstrInfoEmitter::emitOperandNameMappings(
300300
assert(MaxOperandNo <= INT16_MAX &&
301301
"Too many operands for the operand name -> index table");
302302
StringRef Type = MaxOperandNo <= INT8_MAX ? "int8_t" : "int16_t";
303-
OS << " static constexpr " << Type << " OperandMap[][" << NumOperandNames
304-
<< "] = {\n";
303+
OS << " static constexpr " << Type << " OperandMap[]["
304+
<< NumOperandNames + 1 << "] = {\n";
305305
for (const auto &Entry : OperandMap) {
306306
const std::map<unsigned, unsigned> &OpList = Entry.first;
307307

@@ -311,7 +311,8 @@ void InstrInfoEmitter::emitOperandNameMappings(
311311
auto Iter = OpList.find(ID);
312312
OS << (Iter != OpList.end() ? (int)Iter->second : -1) << ", ";
313313
}
314-
OS << "},\n";
314+
// value for OPERAND_LAST
315+
OS << "-1 },\n";
315316
}
316317
OS << " };\n";
317318

0 commit comments

Comments
 (0)