Fix integer overflow for widening addition PiperOrigin-RevId: 879258854 Change-Id: Ied83d7ca7609a21ce10ee466e96131030f7cdd37
diff --git a/riscv/riscv_i_instructions.cc b/riscv/riscv_i_instructions.cc index baf0afe..ecdd6bf 100644 --- a/riscv/riscv_i_instructions.cc +++ b/riscv/riscv_i_instructions.cc
@@ -201,7 +201,7 @@ void RiscVIAddw(const Instruction* instruction) { RiscVBinaryOp<RegisterType, IntReg, NarrowIntReg>( instruction, [](NarrowIntReg a, NarrowIntReg b) { - IntReg c = static_cast<IntReg>(a + b); + IntReg c = static_cast<IntReg>(a) + static_cast<IntReg>(b); return c; }); }