Skip to content

Commit 8d8d0a7

Browse files
committedFeb 22, 2018
[RISCV][NFC] Make logic in RISCVMCCodeEmitter::getImmOpValue more defensive
As pointed out by @sabuasal in a comment on D23568, the logic in RISCVMCCodeEmitter::getImmOpValue could be more defensive. Although with the current instruction definitions it is always the case that `VK_RISCV_LO` is always used with either an I- or S-format instruction, this may not always be the case in the future. Add a check to ensure we will get an assertion in debug builds if that changes. llvm-svn: 325775
1 parent 568e17f commit 8d8d0a7

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed
 

‎llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,24 @@ unsigned RISCVMCCodeEmitter::getImmOpValue(const MCInst &MI, unsigned OpNo,
161161
case RISCVMCExpr::VK_RISCV_Invalid:
162162
llvm_unreachable("Unhandled fixup kind!");
163163
case RISCVMCExpr::VK_RISCV_LO:
164-
FixupKind = MIFrm == RISCVII::InstFormatI ? RISCV::fixup_riscv_lo12_i
165-
: RISCV::fixup_riscv_lo12_s;
164+
if (MIFrm == RISCVII::InstFormatI)
165+
FixupKind = RISCV::fixup_riscv_lo12_i;
166+
else if (MIFrm == RISCVII::InstFormatS)
167+
FixupKind = RISCV::fixup_riscv_lo12_s;
168+
else
169+
llvm_unreachable("VK_RISCV_LO used with unexpected instruction format");
166170
break;
167171
case RISCVMCExpr::VK_RISCV_HI:
168172
FixupKind = RISCV::fixup_riscv_hi20;
169173
break;
170174
case RISCVMCExpr::VK_RISCV_PCREL_LO:
171-
FixupKind = MIFrm == RISCVII::InstFormatI
172-
? RISCV::fixup_riscv_pcrel_lo12_i
173-
: RISCV::fixup_riscv_pcrel_lo12_s;
175+
if (MIFrm == RISCVII::InstFormatI)
176+
FixupKind = RISCV::fixup_riscv_pcrel_lo12_i;
177+
else if (MIFrm == RISCVII::InstFormatS)
178+
FixupKind = RISCV::fixup_riscv_pcrel_lo12_s;
179+
else
180+
llvm_unreachable(
181+
"VK_RISCV_PCREL_LO used with unexpected instruction format");
174182
break;
175183
case RISCVMCExpr::VK_RISCV_PCREL_HI:
176184
FixupKind = RISCV::fixup_riscv_pcrel_hi20;

0 commit comments

Comments
 (0)