[PATCH] D126288: [TableGen][CodeEmitterGen] Do not crash on insufficient positional instruction operands.
Ivan Kosarev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 9 03:54:50 PDT 2022
kosarev added inline comments.
================
Comment at: llvm/utils/TableGen/CodeEmitterGen.cpp:124
- if (NumberedOp >= CGI.Operands.back().MIOperandNo +
- CGI.Operands.back().MINumOperands) {
- errs() << "Too few operands in record " << R->getName() <<
- " (no match for variable " << VarName << "):\n";
- errs() << *R;
- errs() << '\n';
-
- return;
- }
+ if (NumberedOp >=
+ CGI.Operands.back().MIOperandNo + CGI.Operands.back().MINumOperands) {
----------------
foad wrote:
> Do I understand correctly: the fix is to do this check even if the "while" loop above executed 0 times?
Yes. With the original code control may reach the `OpIdx = NumberedOp++;` below several times. As the index gets increased every time, it can at some point become equal to the total number of operands, meaning we would never enter the loop.
Doing `PrintFatalError()` as the patch intends makes it impossible to catch the error twice, but it still feels better to have the check outside of the loop.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D126288/new/
https://reviews.llvm.org/D126288
More information about the llvm-commits
mailing list