-
Notifications
You must be signed in to change notification settings - Fork 15k
[ARM] Verify that disassembled instruction is correct #157360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1365,24 +1365,6 @@ static DecodeStatus DecodeRFEInstruction(MCInst &Inst, unsigned Insn, | |
| DecodeStatus S = MCDisassembler::Success; | ||
|
|
||
| unsigned Rn = fieldFromInstruction(Insn, 16, 4); | ||
| unsigned mode = fieldFromInstruction(Insn, 23, 2); | ||
|
|
||
| switch (mode) { | ||
| case 0: | ||
| mode = ARM_AM::da; | ||
| break; | ||
| case 1: | ||
| mode = ARM_AM::ia; | ||
| break; | ||
| case 2: | ||
| mode = ARM_AM::db; | ||
| break; | ||
| case 3: | ||
| mode = ARM_AM::ib; | ||
| break; | ||
| } | ||
|
|
||
| Inst.addOperand(MCOperand::createImm(mode)); | ||
| if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) | ||
| return MCDisassembler::Fail; | ||
|
|
||
|
|
@@ -2779,10 +2761,6 @@ static DecodeStatus DecodeMVEModImmInstruction(MCInst &Inst, unsigned Insn, | |
|
|
||
| Inst.addOperand(MCOperand::createImm(imm)); | ||
|
|
||
| Inst.addOperand(MCOperand::createImm(ARMVCC::None)); | ||
| Inst.addOperand(MCOperand::createReg(0)); | ||
| Inst.addOperand(MCOperand::createImm(0)); | ||
|
|
||
| return S; | ||
| } | ||
|
|
||
|
|
@@ -2807,7 +2785,6 @@ static DecodeStatus DecodeMVEVADCInstruction(MCInst &Inst, unsigned Insn, | |
| return MCDisassembler::Fail; | ||
| if (!fieldFromInstruction(Insn, 12, 1)) // I bit clear => need input FPSCR | ||
| Inst.addOperand(MCOperand::createReg(ARM::FPSCR_NZCV)); | ||
| Inst.addOperand(MCOperand::createImm(Qd)); | ||
|
|
||
| return S; | ||
| } | ||
|
|
@@ -5956,10 +5933,6 @@ static DecodeStatus DecodeMVEVCMP(MCInst &Inst, unsigned Insn, uint64_t Address, | |
| if (!Check(S, predicate_decoder(Inst, fc, Address, Decoder))) | ||
| return MCDisassembler::Fail; | ||
|
|
||
| Inst.addOperand(MCOperand::createImm(ARMVCC::None)); | ||
| Inst.addOperand(MCOperand::createReg(0)); | ||
| Inst.addOperand(MCOperand::createImm(0)); | ||
|
|
||
| return S; | ||
| } | ||
|
|
||
|
|
@@ -6103,9 +6076,23 @@ DecodeStatus ARMDisassembler::getInstruction(MCInst &MI, uint64_t &Size, | |
| ArrayRef<uint8_t> Bytes, | ||
| uint64_t Address, | ||
| raw_ostream &CS) const { | ||
| DecodeStatus S; | ||
| if (STI.hasFeature(ARM::ModeThumb)) | ||
| return getThumbInstruction(MI, Size, Bytes, Address, CS); | ||
| return getARMInstruction(MI, Size, Bytes, Address, CS); | ||
| S = getThumbInstruction(MI, Size, Bytes, Address, CS); | ||
| else | ||
| S = getARMInstruction(MI, Size, Bytes, Address, CS); | ||
| if (S == DecodeStatus::Fail) | ||
| return S; | ||
|
|
||
| // Verify that the decoded instruction has the correct number of operands. | ||
| const MCInstrDesc &MCID = MCII->get(MI.getOpcode()); | ||
| if (!MCID.isVariadic() && MI.getNumOperands() != MCID.getNumOperands()) { | ||
| reportFatalInternalError(MCII->getName(MI.getOpcode()) + ": expected " + | ||
| Twine(MCID.getNumOperands()) + " operands, got " + | ||
| Twine(MI.getNumOperands()) + "\n"); | ||
| } | ||
|
|
||
| return S; | ||
| } | ||
|
|
||
| DecodeStatus ARMDisassembler::getARMInstruction(MCInst &MI, uint64_t &Size, | ||
|
|
@@ -6144,7 +6131,7 @@ DecodeStatus ARMDisassembler::getARMInstruction(MCInst &MI, uint64_t &Size, | |
| const DecodeTable Tables[] = { | ||
| {DecoderTableVFP32, false}, {DecoderTableVFPV832, false}, | ||
| {DecoderTableNEONData32, true}, {DecoderTableNEONLoadStore32, true}, | ||
| {DecoderTableNEONDup32, true}, {DecoderTablev8NEON32, false}, | ||
| {DecoderTableNEONDup32, false}, {DecoderTablev8NEON32, false}, | ||
| {DecoderTablev8Crypto32, false}, | ||
| }; | ||
|
|
||
|
|
@@ -6154,8 +6141,10 @@ DecodeStatus ARMDisassembler::getARMInstruction(MCInst &MI, uint64_t &Size, | |
| Size = 4; | ||
| // Add a fake predicate operand, because we share these instruction | ||
| // definitions with Thumb2 where these instructions are predicable. | ||
| if (Table.DecodePred && !DecodePredicateOperand(MI, 0xE, Address, this)) | ||
| return MCDisassembler::Fail; | ||
| if (Table.DecodePred && MCII->get(MI.getOpcode()).isPredicable()) { | ||
| MI.addOperand(MCOperand::createImm(ARMCC::AL)); | ||
| MI.addOperand(MCOperand::createReg(ARM::NoRegister)); | ||
| } | ||
| return Result; | ||
| } | ||
| } | ||
|
|
@@ -6189,8 +6178,6 @@ void ARMDisassembler::AddThumb1SBit(MCInst &MI, bool InITBlock) const { | |
| return; | ||
| } | ||
| } | ||
|
|
||
| MI.insert(I, MCOperand::createReg(InITBlock ? ARM::NoRegister : ARM::CPSR)); | ||
| } | ||
|
|
||
| bool ARMDisassembler::isVectorPredicable(const MCInst &MI) const { | ||
|
|
@@ -6491,7 +6478,6 @@ DecodeStatus ARMDisassembler::getThumbInstruction(MCInst &MI, uint64_t &Size, | |
| STI); | ||
| if (Result != MCDisassembler::Fail) { | ||
| Size = 4; | ||
| Check(Result, AddThumbPredicate(MI)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about this change. Also, Note that we don't call this method for instructions in The tests magically pass, but that doesn't give me 100% confidence in this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I've figure it out. I should call |
||
| return Result; | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this should be a fatal error. Maybe report an error and continue? In case there are bugs not detected by tests.