Skip to content

Commit f8ea29f

Browse files
committed
[ARM] Fix a few disassembler bugs
1 parent ac60477 commit f8ea29f

File tree

2 files changed

+22
-36
lines changed

2 files changed

+22
-36
lines changed

llvm/lib/Target/ARM/Disassembler/ARMDisassembler.cpp

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,24 +1365,6 @@ static DecodeStatus DecodeRFEInstruction(MCInst &Inst, unsigned Insn,
13651365
DecodeStatus S = MCDisassembler::Success;
13661366

13671367
unsigned Rn = fieldFromInstruction(Insn, 16, 4);
1368-
unsigned mode = fieldFromInstruction(Insn, 23, 2);
1369-
1370-
switch (mode) {
1371-
case 0:
1372-
mode = ARM_AM::da;
1373-
break;
1374-
case 1:
1375-
mode = ARM_AM::ia;
1376-
break;
1377-
case 2:
1378-
mode = ARM_AM::db;
1379-
break;
1380-
case 3:
1381-
mode = ARM_AM::ib;
1382-
break;
1383-
}
1384-
1385-
Inst.addOperand(MCOperand::createImm(mode));
13861368
if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
13871369
return MCDisassembler::Fail;
13881370

@@ -2779,10 +2761,6 @@ static DecodeStatus DecodeMVEModImmInstruction(MCInst &Inst, unsigned Insn,
27792761

27802762
Inst.addOperand(MCOperand::createImm(imm));
27812763

2782-
Inst.addOperand(MCOperand::createImm(ARMVCC::None));
2783-
Inst.addOperand(MCOperand::createReg(0));
2784-
Inst.addOperand(MCOperand::createImm(0));
2785-
27862764
return S;
27872765
}
27882766

@@ -2807,7 +2785,6 @@ static DecodeStatus DecodeMVEVADCInstruction(MCInst &Inst, unsigned Insn,
28072785
return MCDisassembler::Fail;
28082786
if (!fieldFromInstruction(Insn, 12, 1)) // I bit clear => need input FPSCR
28092787
Inst.addOperand(MCOperand::createReg(ARM::FPSCR_NZCV));
2810-
Inst.addOperand(MCOperand::createImm(Qd));
28112788

28122789
return S;
28132790
}
@@ -5956,10 +5933,6 @@ static DecodeStatus DecodeMVEVCMP(MCInst &Inst, unsigned Insn, uint64_t Address,
59565933
if (!Check(S, predicate_decoder(Inst, fc, Address, Decoder)))
59575934
return MCDisassembler::Fail;
59585935

5959-
Inst.addOperand(MCOperand::createImm(ARMVCC::None));
5960-
Inst.addOperand(MCOperand::createReg(0));
5961-
Inst.addOperand(MCOperand::createImm(0));
5962-
59635936
return S;
59645937
}
59655938

@@ -6103,9 +6076,23 @@ DecodeStatus ARMDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
61036076
ArrayRef<uint8_t> Bytes,
61046077
uint64_t Address,
61056078
raw_ostream &CS) const {
6079+
DecodeStatus S;
61066080
if (STI.hasFeature(ARM::ModeThumb))
6107-
return getThumbInstruction(MI, Size, Bytes, Address, CS);
6108-
return getARMInstruction(MI, Size, Bytes, Address, CS);
6081+
S = getThumbInstruction(MI, Size, Bytes, Address, CS);
6082+
else
6083+
S = getARMInstruction(MI, Size, Bytes, Address, CS);
6084+
if (S == DecodeStatus::Fail)
6085+
return S;
6086+
6087+
// Verify that the decoded instruction has the correct number of operands.
6088+
const MCInstrDesc &MCID = MCII->get(MI.getOpcode());
6089+
if (!MCID.isVariadic() && MI.getNumOperands() != MCID.getNumOperands()) {
6090+
reportFatalInternalError(MCII->getName(MI.getOpcode()) + ": expected " +
6091+
Twine(MCID.getNumOperands()) + " operands, got " +
6092+
Twine(MI.getNumOperands()) + "\n");
6093+
}
6094+
6095+
return S;
61096096
}
61106097

61116098
DecodeStatus ARMDisassembler::getARMInstruction(MCInst &MI, uint64_t &Size,
@@ -6144,7 +6131,7 @@ DecodeStatus ARMDisassembler::getARMInstruction(MCInst &MI, uint64_t &Size,
61446131
const DecodeTable Tables[] = {
61456132
{DecoderTableVFP32, false}, {DecoderTableVFPV832, false},
61466133
{DecoderTableNEONData32, true}, {DecoderTableNEONLoadStore32, true},
6147-
{DecoderTableNEONDup32, true}, {DecoderTablev8NEON32, false},
6134+
{DecoderTableNEONDup32, false}, {DecoderTablev8NEON32, false},
61486135
{DecoderTablev8Crypto32, false},
61496136
};
61506137

@@ -6154,8 +6141,10 @@ DecodeStatus ARMDisassembler::getARMInstruction(MCInst &MI, uint64_t &Size,
61546141
Size = 4;
61556142
// Add a fake predicate operand, because we share these instruction
61566143
// definitions with Thumb2 where these instructions are predicable.
6157-
if (Table.DecodePred && !DecodePredicateOperand(MI, 0xE, Address, this))
6158-
return MCDisassembler::Fail;
6144+
if (Table.DecodePred && MCII->get(MI.getOpcode()).isPredicable()) {
6145+
MI.addOperand(MCOperand::createImm(ARMCC::AL));
6146+
MI.addOperand(MCOperand::createReg(ARM::NoRegister));
6147+
}
61596148
return Result;
61606149
}
61616150
}
@@ -6189,8 +6178,6 @@ void ARMDisassembler::AddThumb1SBit(MCInst &MI, bool InITBlock) const {
61896178
return;
61906179
}
61916180
}
6192-
6193-
MI.insert(I, MCOperand::createReg(InITBlock ? ARM::NoRegister : ARM::CPSR));
61946181
}
61956182

61966183
bool ARMDisassembler::isVectorPredicable(const MCInst &MI) const {
@@ -6491,7 +6478,6 @@ DecodeStatus ARMDisassembler::getThumbInstruction(MCInst &MI, uint64_t &Size,
64916478
STI);
64926479
if (Result != MCDisassembler::Fail) {
64936480
Size = 4;
6494-
Check(Result, AddThumbPredicate(MI));
64956481
return Result;
64966482
}
64976483
}

llvm/test/MC/Disassembler/ARM/arm-tests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@
354354
# CHECK: strheq r0, [r0, -r0]
355355
0xb0 0x00 0x00 0x01
356356

357-
# CHECK: rfedb #4!
357+
# CHECK: rfedb r2!
358358
0x14 0x0 0x32 0xf9
359359

360360
# CHECK: stc2l p0, c0, [r2], #-96

0 commit comments

Comments
 (0)