From ec41000dadd5256fd90f0bfdc97264946e50a3aa Mon Sep 17 00:00:00 2001 From: Andreas Hansson Date: Sat, 27 Sep 2014 09:08:37 -0400 Subject: arm: Fixed undefined behaviours identified by gcc This patch fixes the runtime errors highlighted by the undefined behaviour sanitizer. In the end there were two issues. First, when rotating an immediate, we ended up shifting an uint32_t by 32 in some cases. This case is fixed by checking for a rotation by 0 positions. Second, the Mrc15 and Mcr15 are operating on an IntReg and a MiscReg, but we used the type RegRegImmOp and passed a MiscRegIndex as an IntRegIndex. This issue is resolved by introducing a MiscRegRegImmOp and RegMiscRegImmOp with the appropriate types. With these fixes there are no runtime errors identified for the full ARM regressions. --- src/arch/arm/insts/pred_inst.hh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/arch/arm/insts/pred_inst.hh') diff --git a/src/arch/arm/insts/pred_inst.hh b/src/arch/arm/insts/pred_inst.hh index c5e2ab386..8a335879b 100644 --- a/src/arch/arm/insts/pred_inst.hh +++ b/src/arch/arm/insts/pred_inst.hh @@ -48,10 +48,11 @@ namespace ArmISA { static inline uint32_t -rotate_imm(uint32_t immValue, int rotateValue) +rotate_imm(uint32_t immValue, uint32_t rotateValue) { - return ((immValue >> (rotateValue & 31)) | - (immValue << (32 - (rotateValue & 31)))); + rotateValue &= 31; + return rotateValue == 0 ? immValue : + (immValue >> rotateValue) | (immValue << (32 - rotateValue)); } static inline uint32_t -- cgit v1.2.3