Skip to content

Commit d0b9d78

Browse files
committed
[MC][Mips] Fix wrong assumption about Immediate operand.
While trying to evaluate the branch of this MIPS (EL) non-branch instruction: `ldxc1 $f2, $4($7)` the function fails on the assert: `assert(isImm() && ...)`. This commit ensures that the operand is an immediate before accessing the value. - Triple: `mipsel-unknown-linux-gnu-elf` with '+mips32r2' - Instruction: `ldxc1 $f2, $4($7)` - Raw instruction: `0x81, 0x0, 0xe4, 0x4c`
1 parent a9eb8f0 commit d0b9d78

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

llvm/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,13 @@ class MipsMCInstrAnalysis : public MCInstrAnalysis {
143143
switch (Info->get(Inst.getOpcode()).operands()[NumOps - 1].OperandType) {
144144
case MCOI::OPERAND_UNKNOWN:
145145
case MCOI::OPERAND_IMMEDIATE: {
146+
const MCOperand& Op = Inst.getOperand(NumOps - 1);
147+
if (!Op.isImm())
148+
return false;
146149
// j, jal, jalx, jals
147150
// Absolute branch within the current 256 MB-aligned region
148151
uint64_t Region = Addr & ~uint64_t(0xfffffff);
149-
Target = Region + Inst.getOperand(NumOps - 1).getImm();
152+
Target = Region + Op.getImm();
150153
return true;
151154
}
152155
case MCOI::OPERAND_PCREL:

0 commit comments

Comments
 (0)