This is an archive of the discontinued LLVM Phabricator instance.

[TableGen][CodeEmitterGen] Do not crash on insufficient positional instruction operands.
ClosedPublic

Authored by kosarev on May 24 2022, 4:07 AM.

Diff Detail

Event Timeline

kosarev created this revision.May 24 2022, 4:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2022, 4:07 AM
kosarev requested review of this revision.May 24 2022, 4:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2022, 4:07 AM
kosarev retitled this revision from [TableGen] Do not crash on insufficient positional instruction operands. to [TableGen][CodeEmitterGen] Do not crash on insufficient positional instruction operands..
lattner resigned from this revision.May 24 2022, 10:56 AM

I'm not up to speed on this code: is the current convention for tblgen to exit(1) after errors? If so, this looks reasonable to me.

kosarev updated this revision to Diff 431947.May 25 2022, 5:18 AM

Right, reworked to use TableGen's PrintFatalError(). Thanks.

Adding more reviewers in hope someone may have a chance to take a look.

foad added a subscriber: foad.Jun 9 2022, 3:01 AM
foad added inline comments.
llvm/utils/TableGen/CodeEmitterGen.cpp
124–131

Do I understand correctly: the fix is to do this check even if the "while" loop above executed 0 times?

kosarev added inline comments.Jun 9 2022, 3:54 AM
llvm/utils/TableGen/CodeEmitterGen.cpp
124–131

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.

foad accepted this revision.Jun 9 2022, 5:10 AM
This revision is now accepted and ready to land.Jun 9 2022, 5:10 AM
This revision was landed with ongoing or failed builds.Jun 10 2022, 6:39 AM
This revision was automatically updated to reflect the committed changes.