aboutsummaryrefslogtreecommitdiff
path: root/gcc/config
diff options
context:
space:
mode:
authorPaolo Bonzini <bonzini@gnu.org>2009-04-22 09:01:43 +0000
committerPaolo Bonzini <bonzini@gcc.gnu.org>2009-04-22 09:01:43 +0000
commit6c34a0921352e7ed6058aadf4c950ec700375794 (patch)
treeca5e7d0e19e36c635d191a01bb8fbb1a7afbfb43 /gcc/config
parentbaa48dfaed600d9bc9340e88ea7f0d8ba87cee00 (diff)
downloadgcc-6c34a0921352e7ed6058aadf4c950ec700375794.zip
gcc-6c34a0921352e7ed6058aadf4c950ec700375794.tar.gz
gcc-6c34a0921352e7ed6058aadf4c950ec700375794.tar.bz2
sh.c (shift_insns_rtx, [...]): Truncate shift counts to avoid out-of-bounds array accesses.
2009-04-22 Paolo Bonzini <bonzini@gnu.org> * config/sh/sh.c (shift_insns_rtx, shiftcosts, gen_shifty_op, sh_dynamicalize_shift_p, shl_and_scr_length): Truncate shift counts to avoid out-of-bounds array accesses. From-SVN: r146553
Diffstat (limited to 'gcc/config')
-rw-r--r--gcc/config/sh/sh.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c
index 9d573e0..ce45898 100644
--- a/gcc/config/sh/sh.c
+++ b/gcc/config/sh/sh.c
@@ -2247,7 +2247,7 @@ int
shift_insns_rtx (rtx insn)
{
rtx set_src = SET_SRC (XVECEXP (PATTERN (insn), 0, 0));
- int shift_count = INTVAL (XEXP (set_src, 1));
+ int shift_count = INTVAL (XEXP (set_src, 1)) & 31;
enum rtx_code shift_code = GET_CODE (set_src);
switch (shift_code)
@@ -2286,9 +2286,10 @@ shiftcosts (rtx x)
if (GET_CODE (XEXP (x, 1)) != CONST_INT)
return SH_DYNAMIC_SHIFT_COST;
- value = INTVAL (XEXP (x, 1));
+ /* Otherwise, return the true cost in instructions. Cope with out of range
+ shift counts more or less arbitrarily. */
+ value = INTVAL (XEXP (x, 1)) & 31;
- /* Otherwise, return the true cost in instructions. */
if (GET_CODE (x) == ASHIFTRT)
{
int cost = ashiftrt_insns[value];
@@ -2637,7 +2638,7 @@ gen_shifty_op (int code, rtx *operands)
int max, i;
/* Truncate the shift count in case it is out of bounds. */
- value = value & 0x1f;
+ value = value & 31;
if (value == 31)
{
@@ -2790,7 +2791,7 @@ expand_ashiftrt (rtx *operands)
int
sh_dynamicalize_shift_p (rtx count)
{
- return shift_insns[INTVAL (count)] > 1 + SH_DYNAMIC_SHIFT_COST;
+ return shift_insns[INTVAL (count) & 31] > 1 + SH_DYNAMIC_SHIFT_COST;
}
/* Try to find a good way to implement the combiner pattern
@@ -2950,11 +2951,11 @@ int
shl_and_scr_length (rtx insn)
{
rtx set_src = SET_SRC (XVECEXP (PATTERN (insn), 0, 0));
- int len = shift_insns[INTVAL (XEXP (set_src, 1))];
+ int len = shift_insns[INTVAL (XEXP (set_src, 1)) & 31];
rtx op = XEXP (set_src, 0);
- len += shift_insns[INTVAL (XEXP (op, 1))] + 1;
+ len += shift_insns[INTVAL (XEXP (op, 1)) & 31] + 1;
op = XEXP (XEXP (op, 0), 0);
- return len + shift_insns[INTVAL (XEXP (op, 1))];
+ return len + shift_insns[INTVAL (XEXP (op, 1)) & 31];
}
/* Generate rtl for instructions for which shl_and_kind advised a particular