[Lldb-commits] [lldb] r342008 - [MIPS] Fix signed overflow in DADDIU emulation
Vedant Kumar via lldb-commits
lldb-commits at lists.llvm.org
Tue Sep 11 16:04:05 PDT 2018
Author: vedantk
Date: Tue Sep 11 16:04:05 2018
New Revision: 342008
URL: http://llvm.org/viewvc/llvm-project?rev=342008&view=rev
Log:
[MIPS] Fix signed overflow in DADDIU emulation
This fixes a signed integer overflow diagnostic reported by ubsan.
rdar://44353380
Modified:
lldb/trunk/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp
Modified: lldb/trunk/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp?rev=342008&r1=342007&r2=342008&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp (original)
+++ lldb/trunk/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp Tue Sep 11 16:04:05 2018
@@ -1099,13 +1099,24 @@ bool EmulateInstructionMIPS64::Emulate_D
Context context;
/* read <src> register */
- const int64_t src_opd_val = ReadRegisterUnsigned(
+ const uint64_t src_opd_val = ReadRegisterUnsigned(
eRegisterKindDWARF, dwarf_zero_mips64 + src, 0, &success);
if (!success)
return false;
/* Check if this is daddiu sp, sp, imm16 */
if (dst == dwarf_sp_mips64) {
+ /*
+ * From the MIPS IV spec:
+ *
+ * The term âunsignedâ in the instruction name is a misnomer; this
+ * operation is 64-bit modulo arithmetic that does not trap on overflow.
+ * It is appropriate for arithmetic which is not signed, such as address
+ * arithmetic, or integer arithmetic environments that ignore overflow,
+ * such as âCâ language arithmetic.
+ *
+ * Assume 2's complement and rely on unsigned overflow here.
+ */
uint64_t result = src_opd_val + imm;
RegisterInfo reg_info_sp;
More information about the lldb-commits
mailing list