This is an archive of the discontinued LLVM Phabricator instance.

Explicitly clear the MCInst operand list when calling the target disassembler. Otherwise, repeatedly passing in the same MCInst to getInstruction() will append the current instruction's operands to the previous instruction's operands.
ClosedPublic

Authored by dirty on Jul 30 2015, 3:45 PM.

Details

Summary

getInstruction() in the target disassembler will explicitly clear the MCInst operand list. Some targets were already doing this, but not all. Without this change, repeatedly passing in the same MCInst to getInstruction() will append the current instruction's operands to the previous instruction's operands.

Diff Detail

Repository
rL LLVM

Event Timeline

dirty updated this revision to Diff 31083.Jul 30 2015, 3:45 PM
dirty retitled this revision from to Explicitly clear the MCInst operand list when calling the target disassembler. Otherwise, repeatedly passing in the same MCInst to getInstruction() will append the current instruction's operands to the previous instruction's operands..
dirty updated this object.
dirty added a subscriber: llvm-commits.
dirty updated this object.Jul 30 2015, 3:49 PM
uweigand edited edge metadata.Jul 31 2015, 3:41 AM

Wouldn't it be preferable to do the MI.clear() *within* decodeInstruction? It seems odd to define the interface so that every caller must call clear() itself ...

dirty added a comment.Jul 31 2015, 1:15 PM

Wouldn't it be preferable to do the MI.clear() *within* decodeInstruction? It seems odd to define the interface so that every caller must call clear() itself ...

That sounds reasonable. Not every implementation of getInstruction() calls decodeInstruction(), but I can explicitly call MI.clear() in those cases. The only issue is that decodeInstruction() is an auto generated routine.

I'll update my patch.

dirty updated this revision to Diff 31167.Jul 31 2015, 2:26 PM
dirty edited edge metadata.

Revert previous patch implementation. Now, decodeInstruction() calls MI.clear().

In general, this looks good to me. As a stylistic preference, I'd rather place the .clear() calls closer to the initial .setOpcode() calls to keep the sequences that fill in the MCInst close together; see below.

lib/Target/X86/Disassembler/X86Disassembler.cpp
151 ↗(On Diff #31167)

I think this can be pushed down into translateInstruction().

utils/TableGen/FixedLenDecoderEmitter.cpp
2093 ↗(On Diff #31167)

And this can be pushed down into the MCD::OPC_Decode case. (In the MCD::OPC_TryDecode case, we're using a temporary anyway.)

dirty updated this revision to Diff 31270.Aug 3 2015, 2:42 PM
  • Integrate uweigand's feedback: move MI.clear() into MCD::OPC_Decode case and call MI.clear() inside of translateInstruction() for the X86 target.

Looks good to me, thanks.

dirty marked an inline comment as done.Aug 5 2015, 3:25 PM

Anyone else have comments or should I go ahead and commit this?

hfinkel accepted this revision.Aug 10 2015, 2:24 AM
hfinkel edited edge metadata.

LGTM too, please go ahead.

This revision is now accepted and ready to land.Aug 10 2015, 2:24 AM
This revision was automatically updated to reflect the committed changes.