mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-28 07:08:01 +08:00
tic4x-coff: ubsan: various shift UB
* config/tc-tic4x.c (tic4x_gen_to_words): Rewrite mantissa overflow test without UB. Avoid other UB shifts by making them unsigned.
This commit is contained in:
@ -1,3 +1,9 @@
|
|||||||
|
2020-08-30 Alan Modra <amodra@gmail.com>
|
||||||
|
|
||||||
|
* config/tc-tic4x.c (tic4x_gen_to_words): Rewrite mantissa
|
||||||
|
overflow test without UB. Avoid other UB shifts by making them
|
||||||
|
unsigned.
|
||||||
|
|
||||||
2020-08-31 Cooper Qu <cooper.qu@linux.alibaba.com>
|
2020-08-31 Cooper Qu <cooper.qu@linux.alibaba.com>
|
||||||
|
|
||||||
* config/tc-csky.c (csky_error_state): New member 'arg_int'.
|
* config/tc-csky.c (csky_error_state): New member 'arg_int'.
|
||||||
|
@ -453,8 +453,8 @@ tic4x_gen_to_words (FLONUM_TYPE flonum, LITTLENUM_TYPE *words, int precision)
|
|||||||
/* Store the mantissa data into smant and the roundbit into rbit */
|
/* Store the mantissa data into smant and the roundbit into rbit */
|
||||||
for (p = flonum.leader; p >= flonum.low && shift > -16; p--)
|
for (p = flonum.leader; p >= flonum.low && shift > -16; p--)
|
||||||
{
|
{
|
||||||
tmp = shift >= 0 ? *p << shift : *p >> -shift;
|
tmp = shift >= 0 ? (unsigned) *p << shift : (unsigned) *p >> -shift;
|
||||||
rbit = shift < 0 ? ((*p >> (-shift-1)) & 0x1) : 0;
|
rbit = shift < 0 ? (((unsigned) *p >> (-shift-1)) & 0x1) : 0;
|
||||||
smant |= tmp;
|
smant |= tmp;
|
||||||
shift -= 16;
|
shift -= 16;
|
||||||
}
|
}
|
||||||
@ -463,18 +463,14 @@ tic4x_gen_to_words (FLONUM_TYPE flonum, LITTLENUM_TYPE *words, int precision)
|
|||||||
if(rbit)
|
if(rbit)
|
||||||
{
|
{
|
||||||
/* If the mantissa is going to overflow when added, lets store
|
/* If the mantissa is going to overflow when added, lets store
|
||||||
the extra bit in mover. -- A special case exists when
|
the extra bit in mover. */
|
||||||
mantissa_bits is 31 (E_PRECISION). Then the first test cannot
|
if (smant == (1u << mantissa_bits << 1) - 1)
|
||||||
be trusted, as result is host-dependent, thus the second
|
|
||||||
test. */
|
|
||||||
if( smant == ((unsigned)(1<<(mantissa_bits+1))-1)
|
|
||||||
|| smant == (unsigned)-1 ) /* This is to catch E_PRECISION cases */
|
|
||||||
mover=1;
|
mover=1;
|
||||||
smant++;
|
smant++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the scaled one value */
|
/* Get the scaled one value */
|
||||||
sone = (1 << (mantissa_bits));
|
sone = 1u << mantissa_bits;
|
||||||
|
|
||||||
/* The number may be unnormalised so renormalise it... */
|
/* The number may be unnormalised so renormalise it... */
|
||||||
if(mover)
|
if(mover)
|
||||||
@ -527,7 +523,7 @@ tic4x_gen_to_words (FLONUM_TYPE flonum, LITTLENUM_TYPE *words, int precision)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Insert the exponent data into the word */
|
/* Insert the exponent data into the word */
|
||||||
sfract |= exponent << (mantissa_bits+1);
|
sfract |= (unsigned) exponent << (mantissa_bits + 1);
|
||||||
|
|
||||||
if (precision == S_PRECISION)
|
if (precision == S_PRECISION)
|
||||||
words[0] = sfract;
|
words[0] = sfract;
|
||||||
|
Reference in New Issue
Block a user