Skip to content

Commit c3d3cef

Browse files
authored
[RISCV] Don't delete all fixups in RISCVMCCodeEmitter::expandLongCondBr. (llvm#109513)
The Fixups vector passed into this function may already have fixups in it from earlier instructions. We should not erase those. We just want to erase fixups added by this function. Fixes llvm#108612.
1 parent 80cdc37 commit c3d3cef

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,18 @@ void RISCVMCCodeEmitter::expandLongCondBr(const MCInst &MI,
283283
Offset = 4;
284284
}
285285

286+
// Save the number fixups.
287+
size_t FixupStartIndex = Fixups.size();
288+
286289
// Emit an unconditional jump to the destination.
287290
MCInst TmpInst =
288291
MCInstBuilder(RISCV::JAL).addReg(RISCV::X0).addOperand(SrcSymbol);
289292
uint32_t Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
290293
support::endian::write(CB, Binary, llvm::endianness::little);
291294

292-
Fixups.clear();
295+
// Drop any fixup added so we can add the correct one.
296+
Fixups.resize(FixupStartIndex);
297+
293298
if (SrcSymbol.isExpr()) {
294299
Fixups.push_back(MCFixup::create(Offset, SrcSymbol.getExpr(),
295300
MCFixupKind(RISCV::fixup_riscv_jal),

llvm/test/MC/RISCV/rv64-relax-all.s

+6
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ c.beqz a0, NEAR
1414
# INSTR: c.j 0x0 <NEAR>
1515
# RELAX-INSTR: jal zero, 0x0 <NEAR>
1616
c.j NEAR
17+
18+
bnez s0, .foo
19+
j .foo
20+
beqz s0, .foo
21+
.foo:
22+
ret

0 commit comments

Comments
 (0)