Commit 6c34a092 by Paolo Bonzini Committed by Paolo Bonzini

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
parent baa48dfa
2009-04-22 Paolo Bonzini <bonzini@gnu.org> 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.
2009-04-22 Paolo Bonzini <bonzini@gnu.org>
* config/sparc/sparc.h (POINTER_SIZE): Fix comment. * config/sparc/sparc.h (POINTER_SIZE): Fix comment.
(Pmode): Move above. (Pmode): Move above.
......
...@@ -2247,7 +2247,7 @@ int ...@@ -2247,7 +2247,7 @@ int
shift_insns_rtx (rtx insn) shift_insns_rtx (rtx insn)
{ {
rtx set_src = SET_SRC (XVECEXP (PATTERN (insn), 0, 0)); 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); enum rtx_code shift_code = GET_CODE (set_src);
switch (shift_code) switch (shift_code)
...@@ -2286,9 +2286,10 @@ shiftcosts (rtx x) ...@@ -2286,9 +2286,10 @@ shiftcosts (rtx x)
if (GET_CODE (XEXP (x, 1)) != CONST_INT) if (GET_CODE (XEXP (x, 1)) != CONST_INT)
return SH_DYNAMIC_SHIFT_COST; 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) if (GET_CODE (x) == ASHIFTRT)
{ {
int cost = ashiftrt_insns[value]; int cost = ashiftrt_insns[value];
...@@ -2637,7 +2638,7 @@ gen_shifty_op (int code, rtx *operands) ...@@ -2637,7 +2638,7 @@ gen_shifty_op (int code, rtx *operands)
int max, i; int max, i;
/* Truncate the shift count in case it is out of bounds. */ /* Truncate the shift count in case it is out of bounds. */
value = value & 0x1f; value = value & 31;
if (value == 31) if (value == 31)
{ {
...@@ -2790,7 +2791,7 @@ expand_ashiftrt (rtx *operands) ...@@ -2790,7 +2791,7 @@ expand_ashiftrt (rtx *operands)
int int
sh_dynamicalize_shift_p (rtx count) 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 /* Try to find a good way to implement the combiner pattern
...@@ -2950,11 +2951,11 @@ int ...@@ -2950,11 +2951,11 @@ int
shl_and_scr_length (rtx insn) shl_and_scr_length (rtx insn)
{ {
rtx set_src = SET_SRC (XVECEXP (PATTERN (insn), 0, 0)); 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); 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); 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 /* Generate rtl for instructions for which shl_and_kind advised a particular
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment