re PR other/59545 (Signed integer overflow issues)

PR other/59545
	* genattrtab.c (struct attr_hash): Change hashcode type to unsigned.
	(attr_hash_add_rtx, attr_hash_add_string): Change hashcode parameter
	to unsigned.
	(attr_rtx_1): Change hashcode variable to unsigned.
	(attr_string): Likewise.  Perform first multiplication in unsigned
	type.
	* ifcvt.c (noce_try_store_flag_constants): Avoid signed integer
	overflows.
	* double-int.c (neg_double): Likewise.
	* stor-layout.c (set_min_and_max_values_for_integral_type): Likewise.
	* combine.c (force_to_mode): Likewise.
	* postreload.c (move2add_use_add2_insn, move2add_use_add3_insn,
	reload_cse_move2add, move2add_note_store): Likewise.
	* simplify-rtx.c (simplify_const_unary_operation,
	simplify_const_binary_operation): Likewise.
	* ipa-split.c (find_split_points): Initialize first.can_split
	and first.non_ssa_vars.
	* gengtype-state.c (read_state_files_list): Fix up check.
	* genautomata.c (reserv_sets_hash_value): Use portable rotation
	idiom.
java/
	* class.c (hashUtf8String): Compute hash in unsigned type.
	* javaop.h (WORD_TO_INT): Avoid signed integer overflow.

From-SVN: r206134
This commit is contained in:
Jakub Jelinek 2013-12-19 22:27:51 +01:00 committed by Jakub Jelinek
parent d8d79c1df2
commit e15eb172b0
14 changed files with 61 additions and 30 deletions

View File

@ -1,3 +1,27 @@
2013-12-19 Jakub Jelinek <jakub@redhat.com>
PR other/59545
* genattrtab.c (struct attr_hash): Change hashcode type to unsigned.
(attr_hash_add_rtx, attr_hash_add_string): Change hashcode parameter
to unsigned.
(attr_rtx_1): Change hashcode variable to unsigned.
(attr_string): Likewise. Perform first multiplication in unsigned
type.
* ifcvt.c (noce_try_store_flag_constants): Avoid signed integer
overflows.
* double-int.c (neg_double): Likewise.
* stor-layout.c (set_min_and_max_values_for_integral_type): Likewise.
* combine.c (force_to_mode): Likewise.
* postreload.c (move2add_use_add2_insn, move2add_use_add3_insn,
reload_cse_move2add, move2add_note_store): Likewise.
* simplify-rtx.c (simplify_const_unary_operation,
simplify_const_binary_operation): Likewise.
* ipa-split.c (find_split_points): Initialize first.can_split
and first.non_ssa_vars.
* gengtype-state.c (read_state_files_list): Fix up check.
* genautomata.c (reserv_sets_hash_value): Use portable rotation
idiom.
2013-12-19 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
* config/arm/neon-docgen.ml: Add crypto intrinsics documentation.

View File

@ -8200,9 +8200,7 @@ force_to_mode (rtx x, enum machine_mode mode, unsigned HOST_WIDE_INT mask,
/* If X is (minus C Y) where C's least set bit is larger than any bit
in the mask, then we may replace with (neg Y). */
if (CONST_INT_P (XEXP (x, 0))
&& (((unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 0))
& -INTVAL (XEXP (x, 0))))
> mask))
&& ((UINTVAL (XEXP (x, 0)) & -UINTVAL (XEXP (x, 0))) > mask))
{
x = simplify_gen_unary (NEG, GET_MODE (x), XEXP (x, 1),
GET_MODE (x));

View File

@ -138,7 +138,7 @@ neg_double (unsigned HOST_WIDE_INT l1, HOST_WIDE_INT h1,
if (l1 == 0)
{
*lv = 0;
*hv = - h1;
*hv = - (unsigned HOST_WIDE_INT) h1;
return (*hv & h1) < 0;
}
else

View File

@ -320,7 +320,7 @@ static FILE *attr_file, *dfa_file, *latency_file;
struct attr_hash
{
struct attr_hash *next; /* Next structure in the bucket. */
int hashcode; /* Hash code of this rtx or string. */
unsigned int hashcode; /* Hash code of this rtx or string. */
union
{
char *str; /* The string (negative hash codes) */
@ -345,7 +345,7 @@ static struct attr_hash *attr_hash_table[RTL_HASH_SIZE];
/* Add an entry to the hash table for RTL with hash code HASHCODE. */
static void
attr_hash_add_rtx (int hashcode, rtx rtl)
attr_hash_add_rtx (unsigned int hashcode, rtx rtl)
{
struct attr_hash *h;
@ -359,7 +359,7 @@ attr_hash_add_rtx (int hashcode, rtx rtl)
/* Add an entry to the hash table for STRING with hash code HASHCODE. */
static void
attr_hash_add_string (int hashcode, char *str)
attr_hash_add_string (unsigned int hashcode, char *str)
{
struct attr_hash *h;
@ -384,7 +384,7 @@ static rtx
attr_rtx_1 (enum rtx_code code, va_list p)
{
rtx rt_val = NULL_RTX;/* RTX to return to caller... */
int hashcode;
unsigned int hashcode;
struct attr_hash *h;
struct obstack *old_obstack = rtl_obstack;
@ -612,15 +612,15 @@ static char *
attr_string (const char *str, int len)
{
struct attr_hash *h;
int hashcode;
unsigned int hashcode;
int i;
char *new_str;
/* Compute the hash code. */
hashcode = (len + 1) * 613 + (unsigned) str[0];
hashcode = (len + 1) * 613U + (unsigned) str[0];
for (i = 1; i < len; i += 2)
hashcode = ((hashcode * 613) + (unsigned) str[i]);
if (hashcode < 0)
if ((int) hashcode < 0)
hashcode = -hashcode;
/* Search the table for the string. */

View File

@ -3494,7 +3494,7 @@ reserv_sets_hash_value (reserv_sets_t reservs)
{
reservs_num--;
hash_value += ((*reserv_ptr >> i)
| (*reserv_ptr << (sizeof (set_el_t) * CHAR_BIT - i)));
| (*reserv_ptr << ((sizeof (set_el_t) * CHAR_BIT) & -i)));
i++;
if (i == sizeof (set_el_t) * CHAR_BIT)
i = 0;

View File

@ -2651,7 +2651,7 @@ read_state_files_list (void)
"expecting file in !fileslist of state file");
};
t0 = peek_state_token (0);
if (!state_token_kind (t0) == STOK_RIGHTPAR)
if (state_token_kind (t0) != STOK_RIGHTPAR)
fatal_reading_state (t0, "missing ) for !fileslist in state file");
next_state_tokens (1);
}

View File

@ -1112,12 +1112,13 @@ noce_try_store_flag_constants (struct noce_if_info *if_info)
ifalse = INTVAL (if_info->a);
itrue = INTVAL (if_info->b);
diff = (unsigned HOST_WIDE_INT) itrue - ifalse;
/* Make sure we can represent the difference between the two values. */
if ((itrue - ifalse > 0)
if ((diff > 0)
!= ((ifalse < 0) != (itrue < 0) ? ifalse < 0 : ifalse < itrue))
return FALSE;
diff = trunc_int_for_mode (itrue - ifalse, mode);
diff = trunc_int_for_mode (diff, mode);
can_reverse = (reversed_comparison_code (if_info->cond, if_info->jump)
!= UNKNOWN);
@ -1148,7 +1149,7 @@ noce_try_store_flag_constants (struct noce_if_info *if_info)
if (reversep)
{
tmp = itrue; itrue = ifalse; ifalse = tmp;
diff = trunc_int_for_mode (-diff, mode);
diff = trunc_int_for_mode (-(unsigned HOST_WIDE_INT) diff, mode);
}
start_sequence ();

View File

@ -950,7 +950,9 @@ find_split_points (int overall_time, int overall_size)
first.earliest = INT_MAX;
first.set_ssa_names = 0;
first.used_ssa_names = 0;
first.non_ssa_vars = 0;
first.bbs_visited = 0;
first.can_split = false;
stack.safe_push (first);
ENTRY_BLOCK_PTR_FOR_FN (cfun)->aux = (void *)(intptr_t)-1;

View File

@ -1,3 +1,9 @@
2013-12-19 Jakub Jelinek <jakub@redhat.com>
PR other/59545
* class.c (hashUtf8String): Compute hash in unsigned type.
* javaop.h (WORD_TO_INT): Avoid signed integer overflow.
2013-11-22 Andrew MacLeod <amacleod@redhat.com>
* java-gimplify.c: Add required include files from gimple.h.

View File

@ -920,7 +920,7 @@ hashUtf8String (const char *str, int len)
{
const unsigned char* ptr = (const unsigned char*) str;
const unsigned char *limit = ptr + len;
int32 hash = 0;
uint32 hash = 0;
for (; ptr < limit;)
{
int ch = UTF8_GET (ptr, limit);

View File

@ -154,7 +154,7 @@ WORD_TO_INT(jword w)
{
jint n = w & 0xffffffff; /* Mask lower 32 bits. */
n ^= (jint)1 << 31;
n -= (jint)1 << 31; /* Sign extend lower 32 bits to upper. */
n -= (uint32)1 << 31; /* Sign extend lower 32 bits to upper. */
return n;
}

View File

@ -1766,7 +1766,7 @@ move2add_use_add2_insn (rtx reg, rtx sym, rtx off, rtx insn)
rtx pat = PATTERN (insn);
rtx src = SET_SRC (pat);
int regno = REGNO (reg);
rtx new_src = gen_int_mode (INTVAL (off) - reg_offset[regno],
rtx new_src = gen_int_mode (UINTVAL (off) - reg_offset[regno],
GET_MODE (reg));
bool speed = optimize_bb_for_speed_p (BLOCK_FOR_INSN (insn));
bool changed = false;
@ -1866,7 +1866,7 @@ move2add_use_add3_insn (rtx reg, rtx sym, rtx off, rtx insn)
&& reg_symbol_ref[i] != NULL_RTX
&& rtx_equal_p (sym, reg_symbol_ref[i]))
{
rtx new_src = gen_int_mode (INTVAL (off) - reg_offset[i],
rtx new_src = gen_int_mode (UINTVAL (off) - reg_offset[i],
GET_MODE (reg));
/* (set (reg) (plus (reg) (const_int 0))) is not canonical;
use (set (reg) (reg)) instead.
@ -1901,7 +1901,7 @@ move2add_use_add3_insn (rtx reg, rtx sym, rtx off, rtx insn)
tem = gen_rtx_REG (GET_MODE (reg), min_regno);
if (i != min_regno)
{
rtx new_src = gen_int_mode (INTVAL (off) - reg_offset[min_regno],
rtx new_src = gen_int_mode (UINTVAL (off) - reg_offset[min_regno],
GET_MODE (reg));
tem = gen_rtx_PLUS (GET_MODE (reg), tem, new_src);
}
@ -2010,7 +2010,7 @@ reload_cse_move2add (rtx first)
&& CONST_INT_P (XEXP (SET_SRC (set), 1)))
{
rtx src3 = XEXP (SET_SRC (set), 1);
HOST_WIDE_INT added_offset = INTVAL (src3);
unsigned HOST_WIDE_INT added_offset = UINTVAL (src3);
HOST_WIDE_INT base_offset = reg_offset[REGNO (src)];
HOST_WIDE_INT regno_offset = reg_offset[regno];
rtx new_src =
@ -2224,7 +2224,7 @@ move2add_note_store (rtx dst, const_rtx set, void *data)
{
rtx src = SET_SRC (set);
rtx base_reg;
HOST_WIDE_INT offset;
unsigned HOST_WIDE_INT offset;
int base_regno;
switch (GET_CODE (src))
@ -2235,7 +2235,7 @@ move2add_note_store (rtx dst, const_rtx set, void *data)
base_reg = XEXP (src, 0);
if (CONST_INT_P (XEXP (src, 1)))
offset = INTVAL (XEXP (src, 1));
offset = UINTVAL (XEXP (src, 1));
else if (REG_P (XEXP (src, 1))
&& move2add_valid_value_p (REGNO (XEXP (src, 1)), mode))
{

View File

@ -1647,7 +1647,7 @@ simplify_const_unary_operation (enum rtx_code code, enum machine_mode mode,
break;
case NEG:
val = - arg0;
val = - (unsigned HOST_WIDE_INT) arg0;
break;
case ABS:
@ -4117,15 +4117,15 @@ simplify_const_binary_operation (enum rtx_code code, enum machine_mode mode,
switch (code)
{
case PLUS:
val = arg0s + arg1s;
val = (unsigned HOST_WIDE_INT) arg0s + arg1s;
break;
case MINUS:
val = arg0s - arg1s;
val = (unsigned HOST_WIDE_INT) arg0s - arg1s;
break;
case MULT:
val = arg0s * arg1s;
val = (unsigned HOST_WIDE_INT) arg0s * arg1s;
break;
case DIV:

View File

@ -2521,7 +2521,7 @@ set_min_and_max_values_for_integral_type (tree type,
max_value
= build_int_cst_wide (type, precision - HOST_BITS_PER_WIDE_INT >= 0
? -1
: ((HOST_WIDE_INT) 1 << precision) - 1,
: (HOST_WIDE_INT_1U << precision) - 1,
precision - HOST_BITS_PER_WIDE_INT > 0
? ((unsigned HOST_WIDE_INT) ~0
>> (HOST_BITS_PER_WIDE_INT
@ -2534,7 +2534,7 @@ set_min_and_max_values_for_integral_type (tree type,
= build_int_cst_wide (type,
(precision - HOST_BITS_PER_WIDE_INT > 0
? 0
: (HOST_WIDE_INT) (-1) << (precision - 1)),
: HOST_WIDE_INT_M1U << (precision - 1)),
(((HOST_WIDE_INT) (-1)
<< (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
? precision - HOST_BITS_PER_WIDE_INT - 1