diff options
| author | Vedant Kumar <vsk@apple.com> | 2018-09-11 23:04:05 +0000 |
|---|---|---|
| committer | Vedant Kumar <vsk@apple.com> | 2018-09-11 23:04:05 +0000 |
| commit | a4529b00e4228aa152b7dea0e4cedaecce451913 (patch) | |
| tree | 79f18f37659843380373366e39ab8e21e1246327 /lldb | |
| parent | 73e04847bfe7b887cd9a62cb2fd6530cc84bea53 (diff) | |
| download | bcm5719-llvm-a4529b00e4228aa152b7dea0e4cedaecce451913.tar.gz bcm5719-llvm-a4529b00e4228aa152b7dea0e4cedaecce451913.zip | |
[MIPS] Fix signed overflow in DADDIU emulation
This fixes a signed integer overflow diagnostic reported by ubsan.
rdar://44353380
llvm-svn: 342008
Diffstat (limited to 'lldb')
| -rw-r--r-- | lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp b/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp index 17e284e5423..cbf3e7dfca4 100644 --- a/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp +++ b/lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp @@ -1099,13 +1099,24 @@ bool EmulateInstructionMIPS64::Emulate_DADDiu(llvm::MCInst &insn) { 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; |

