Skip to content

Commit 415dd38

Browse files
authored
[RISCV][MC] Correct the register state update for auipc (#130897)
AUIPC is a 20-bits value which is used to form 32-bits offset thus it should be a int32 value, then signed-extend to int64.
1 parent 74f5a02 commit 415dd38

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class RISCVMCInstrAnalysis : public MCInstrAnalysis {
195195
}
196196
case RISCV::AUIPC:
197197
setGPRState(Inst.getOperand(0).getReg(),
198-
Addr + (Inst.getOperand(1).getImm() << 12));
198+
Addr + SignExtend64<32>(Inst.getOperand(1).getImm() << 12));
199199
break;
200200
}
201201
}

llvm/test/tools/llvm-objdump/ELF/RISCV/branches.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,9 @@ nop
7878
bar:
7979
# CHECK: 60: c.nop
8080
nop
81+
82+
# CHECK-LABEL: 00011000 <far>:
83+
.org 0x11000
84+
far:
85+
# CHECK: jalr ra, 0x0(ra) <foo>
86+
call foo

0 commit comments

Comments
 (0)