Skip to content

Commit 68a253d

Browse files
authored
[lldb][RISCV] Use uint64_t for emulating ADDI (#160550)
In RISC-V, the same instruction is used for both signed and unsigned additions. Signed integer overflow is undefined behavior in C++, but signed integer overflow is defined behavior when using ADDI in RISC-V. As we are emulating the RISC-V behavior we should be using uint. This fix the failure with ubsan introduced by #159842: lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp:807:40: runtime error: signed integer overflow: -9223372036854775808 + -16 cannot be represented in type 'int64_t' (aka 'long')
1 parent c1b2110 commit 68a253d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ class Executor {
804804
return transformOptional(
805805
inst.rs1.ReadI64(m_emu),
806806
[&](int64_t rs1) {
807-
int64_t result = rs1 + int64_t(SignExt(inst.imm));
807+
uint64_t result = rs1 + uint64_t(SignExt(inst.imm));
808808
// Check if this is a stack pointer adjustment.
809809
if (inst.rd.rd == RISCV_GPR_SP &&
810810
inst.rs1.rs == RISCV_GPR_SP) {

0 commit comments

Comments
 (0)