* [PATCH] Fix signed integer overflow in gcc/data-streamer.c
@ 2014-09-28 12:22 Markus Trippelsdorf
2014-09-28 12:37 ` Steven Bosscher
0 siblings, 1 reply; 5+ messages in thread
From: Markus Trippelsdorf @ 2014-09-28 12:22 UTC (permalink / raw)
To: gcc-patches; +Cc: Diego Novillo
Running the testsuite with a -fsanitize=undefined instrumented compiler
shows:
% gcc -O2 -flto -fno-use-linker-plugin -flto-partition=none testsuite/gcc.dg/torture/pr28045.c
gcc/data-streamer.c:113:45: runtime error: negation of -9223372036854775808 cannot be represented in type 'long int'; cast to an unsigned type to negate this value to itself
The fix is obvious.
Boostrapped and tested on x86_64-unknown-linux-gnu.
OK for trunk?
Thanks.
2014-09-28 Markus Trippelsdorf <markus@trippelsdorf.de>
* data-streamer.c (bp_unpack_var_len_int): Avoid signed
integer overflow.
diff --git a/gcc/data-streamer.c b/gcc/data-streamer.c
index 0e19c72162aa..0760ed590c22 100644
--- a/gcc/data-streamer.c
+++ b/gcc/data-streamer.c
@@ -110,7 +110,7 @@ bp_unpack_var_len_int (struct bitpack_d *bp)
if ((half_byte & 0x8) == 0)
{
if ((shift < HOST_BITS_PER_WIDE_INT) && (half_byte & 0x4))
- result |= - ((HOST_WIDE_INT)1 << shift);
+ result |= - ((unsigned HOST_WIDE_INT)1 << shift);
return result;
}
--
Markus
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix signed integer overflow in gcc/data-streamer.c
2014-09-28 12:22 [PATCH] Fix signed integer overflow in gcc/data-streamer.c Markus Trippelsdorf
@ 2014-09-28 12:37 ` Steven Bosscher
2014-09-28 12:57 ` [PATCH v2] " Markus Trippelsdorf
0 siblings, 1 reply; 5+ messages in thread
From: Steven Bosscher @ 2014-09-28 12:37 UTC (permalink / raw)
To: Markus Trippelsdorf; +Cc: GCC Patches, Diego Novillo
On Sun, Sep 28, 2014 at 2:22 PM, Markus Trippelsdorf wrote:
> Running the testsuite with a -fsanitize=undefined instrumented compiler
> shows:
> % gcc -O2 -flto -fno-use-linker-plugin -flto-partition=none testsuite/gcc.dg/torture/pr28045.c
> gcc/data-streamer.c:113:45: runtime error: negation of -9223372036854775808 cannot be represented in type 'long int'; cast to an unsigned type to negate this value to itself
>
> The fix is obvious.
>
> Boostrapped and tested on x86_64-unknown-linux-gnu.
> OK for trunk?
> Thanks.
>
> 2014-09-28 Markus Trippelsdorf <markus@trippelsdorf.de>
>
> * data-streamer.c (bp_unpack_var_len_int): Avoid signed
> integer overflow.
>
> diff --git a/gcc/data-streamer.c b/gcc/data-streamer.c
> index 0e19c72162aa..0760ed590c22 100644
> --- a/gcc/data-streamer.c
> +++ b/gcc/data-streamer.c
> @@ -110,7 +110,7 @@ bp_unpack_var_len_int (struct bitpack_d *bp)
> if ((half_byte & 0x8) == 0)
> {
> if ((shift < HOST_BITS_PER_WIDE_INT) && (half_byte & 0x4))
> - result |= - ((HOST_WIDE_INT)1 << shift);
> + result |= - ((unsigned HOST_WIDE_INT)1 << shift);
>
> return result;
> }
Can you use HOST_WIDE_INT_1U for this?
Ciao!
Steven
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] Fix signed integer overflow in gcc/data-streamer.c
2014-09-28 12:37 ` Steven Bosscher
@ 2014-09-28 12:57 ` Markus Trippelsdorf
2014-09-30 7:09 ` Markus Trippelsdorf
0 siblings, 1 reply; 5+ messages in thread
From: Markus Trippelsdorf @ 2014-09-28 12:57 UTC (permalink / raw)
To: Steven Bosscher; +Cc: GCC Patches, Diego Novillo
On 2014.09.28 at 14:36 +0200, Steven Bosscher wrote:
>
> Can you use HOST_WIDE_INT_1U for this?
Sure. Thanks for the suggestion.
(Fix now resembles similar idiom in data-streamer-in.c)
2014-09-28 Markus Trippelsdorf <markus@trippelsdorf.de>
* data-streamer.c (bp_unpack_var_len_int): Avoid signed
integer overflow.
diff --git a/gcc/data-streamer.c b/gcc/data-streamer.c
index 0e19c72162aa..785beb5165fa 100644
--- a/gcc/data-streamer.c
+++ b/gcc/data-streamer.c
@@ -110,7 +110,7 @@ bp_unpack_var_len_int (struct bitpack_d *bp)
if ((half_byte & 0x8) == 0)
{
if ((shift < HOST_BITS_PER_WIDE_INT) && (half_byte & 0x4))
- result |= - ((HOST_WIDE_INT)1 << shift);
+ result |= - (HOST_WIDE_INT_1U << shift);
return result;
}
--
Markus
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] Fix signed integer overflow in gcc/data-streamer.c
2014-09-28 12:57 ` [PATCH v2] " Markus Trippelsdorf
@ 2014-09-30 7:09 ` Markus Trippelsdorf
2014-09-30 15:37 ` Diego Novillo
0 siblings, 1 reply; 5+ messages in thread
From: Markus Trippelsdorf @ 2014-09-30 7:09 UTC (permalink / raw)
To: Steven Bosscher; +Cc: GCC Patches, Diego Novillo
On 2014.09.28 at 14:57 +0200, Markus Trippelsdorf wrote:
> On 2014.09.28 at 14:36 +0200, Steven Bosscher wrote:
> >
> > Can you use HOST_WIDE_INT_1U for this?
>
> Sure. Thanks for the suggestion.
> (Fix now resembles similar idiom in data-streamer-in.c)
I checked in the fix as obvious.
--
Markus
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] Fix signed integer overflow in gcc/data-streamer.c
2014-09-30 7:09 ` Markus Trippelsdorf
@ 2014-09-30 15:37 ` Diego Novillo
0 siblings, 0 replies; 5+ messages in thread
From: Diego Novillo @ 2014-09-30 15:37 UTC (permalink / raw)
To: Markus Trippelsdorf; +Cc: Steven Bosscher, GCC Patches
On Tue, Sep 30, 2014 at 3:09 AM, Markus Trippelsdorf
<markus@trippelsdorf.de> wrote:
> On 2014.09.28 at 14:57 +0200, Markus Trippelsdorf wrote:
>> On 2014.09.28 at 14:36 +0200, Steven Bosscher wrote:
>> >
>> > Can you use HOST_WIDE_INT_1U for this?
>>
>> Sure. Thanks for the suggestion.
>> (Fix now resembles similar idiom in data-streamer-in.c)
>
> I checked in the fix as obvious.
Sorry for the delay. Yes, the fix is obvious. Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-09-30 15:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-28 12:22 [PATCH] Fix signed integer overflow in gcc/data-streamer.c Markus Trippelsdorf
2014-09-28 12:37 ` Steven Bosscher
2014-09-28 12:57 ` [PATCH v2] " Markus Trippelsdorf
2014-09-30 7:09 ` Markus Trippelsdorf
2014-09-30 15:37 ` Diego Novillo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).