* [wide-int] Add more assertions
@ 2014-05-02 19:20 Richard Sandiford
2014-05-03 1:40 ` Kenneth Zadeck
0 siblings, 1 reply; 3+ messages in thread
From: Richard Sandiford @ 2014-05-02 19:20 UTC (permalink / raw)
To: gcc-patches; +Cc: zadeck, mikestump
This patch adds some assertions against sext (.., 0) and zext (..., 0).
The former is undefined at the sext_hwi level and the latter is disallowed
for consistency with the former.
Also, set_bit (rightly IMO) can't handle bit >= precision. For
precision <= HOST_BITS_PER_WIDE_INT it would invoke undefined
behaviour while for other precisions I think it would crash.
A case with precision <= HOST_BITS_PER_WIDE_INT showed up in java
(fix posted separately).
Tested on x86_64-linux-gnu and powerpc64-linux-gnu. OK to install?
Thanks,
Richard
Index: gcc/wide-int.h
===================================================================
--- gcc/wide-int.h 2014-05-02 16:28:09.561842842 +0100
+++ gcc/wide-int.h 2014-05-02 16:44:04.015463718 +0100
@@ -2046,6 +2046,8 @@ wi::sext (const T &x, unsigned int offse
unsigned int precision = get_precision (result);
WIDE_INT_REF_FOR (T) xi (x, precision);
+ gcc_checking_assert (offset != 0);
+
if (offset <= HOST_BITS_PER_WIDE_INT)
{
val[0] = sext_hwi (xi.ulow (), offset);
@@ -2065,6 +2067,8 @@ wi::zext (const T &x, unsigned int offse
unsigned int precision = get_precision (result);
WIDE_INT_REF_FOR (T) xi (x, precision);
+ gcc_checking_assert (offset != 0);
+
/* This is not just an optimization, it is actually required to
maintain canonization. */
if (offset >= precision)
@@ -2102,6 +2106,9 @@ wi::set_bit (const T &x, unsigned int bi
WI_UNARY_RESULT_VAR (result, val, T, x);
unsigned int precision = get_precision (result);
WIDE_INT_REF_FOR (T) xi (x, precision);
+
+ gcc_checking_assert (bit < precision);
+
if (precision <= HOST_BITS_PER_WIDE_INT)
{
val[0] = xi.ulow () | ((unsigned HOST_WIDE_INT) 1 << bit);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [wide-int] Add more assertions
2014-05-02 19:20 [wide-int] Add more assertions Richard Sandiford
@ 2014-05-03 1:40 ` Kenneth Zadeck
2014-05-03 7:00 ` Richard Sandiford
0 siblings, 1 reply; 3+ messages in thread
From: Kenneth Zadeck @ 2014-05-03 1:40 UTC (permalink / raw)
To: gcc-patches, mikestump, rdsandiford
These are fine.
On 05/02/2014 03:20 PM, Richard Sandiford wrote:
> This patch adds some assertions against sext (.., 0) and zext (..., 0).
> The former is undefined at the sext_hwi level and the latter is disallowed
> for consistency with the former.
>
> Also, set_bit (rightly IMO) can't handle bit >= precision. For
> precision <= HOST_BITS_PER_WIDE_INT it would invoke undefined
> behaviour while for other precisions I think it would crash.
> A case with precision <= HOST_BITS_PER_WIDE_INT showed up in java
> (fix posted separately).
>
> Tested on x86_64-linux-gnu and powerpc64-linux-gnu. OK to install?
>
> Thanks,
> Richard
>
>
> Index: gcc/wide-int.h
> ===================================================================
> --- gcc/wide-int.h 2014-05-02 16:28:09.561842842 +0100
> +++ gcc/wide-int.h 2014-05-02 16:44:04.015463718 +0100
> @@ -2046,6 +2046,8 @@ wi::sext (const T &x, unsigned int offse
> unsigned int precision = get_precision (result);
> WIDE_INT_REF_FOR (T) xi (x, precision);
>
> + gcc_checking_assert (offset != 0);
> +
> if (offset <= HOST_BITS_PER_WIDE_INT)
> {
> val[0] = sext_hwi (xi.ulow (), offset);
> @@ -2065,6 +2067,8 @@ wi::zext (const T &x, unsigned int offse
> unsigned int precision = get_precision (result);
> WIDE_INT_REF_FOR (T) xi (x, precision);
>
> + gcc_checking_assert (offset != 0);
> +
> /* This is not just an optimization, it is actually required to
> maintain canonization. */
> if (offset >= precision)
> @@ -2102,6 +2106,9 @@ wi::set_bit (const T &x, unsigned int bi
> WI_UNARY_RESULT_VAR (result, val, T, x);
> unsigned int precision = get_precision (result);
> WIDE_INT_REF_FOR (T) xi (x, precision);
> +
> + gcc_checking_assert (bit < precision);
> +
> if (precision <= HOST_BITS_PER_WIDE_INT)
> {
> val[0] = xi.ulow () | ((unsigned HOST_WIDE_INT) 1 << bit);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [wide-int] Add more assertions
2014-05-03 1:40 ` Kenneth Zadeck
@ 2014-05-03 7:00 ` Richard Sandiford
0 siblings, 0 replies; 3+ messages in thread
From: Richard Sandiford @ 2014-05-03 7:00 UTC (permalink / raw)
To: Kenneth Zadeck; +Cc: gcc-patches, mikestump
Kenneth Zadeck <zadeck@naturalbridge.com> writes:
> These are fine.
Thanks. I'll hold off applying it until the java fix has been reviewed
(which could be after the merge -- no need to hold it up for this IMO).
Richard
>
> On 05/02/2014 03:20 PM, Richard Sandiford wrote:
>> This patch adds some assertions against sext (.., 0) and zext (..., 0).
>> The former is undefined at the sext_hwi level and the latter is disallowed
>> for consistency with the former.
>>
>> Also, set_bit (rightly IMO) can't handle bit >= precision. For
>> precision <= HOST_BITS_PER_WIDE_INT it would invoke undefined
>> behaviour while for other precisions I think it would crash.
>> A case with precision <= HOST_BITS_PER_WIDE_INT showed up in java
>> (fix posted separately).
>>
>> Tested on x86_64-linux-gnu and powerpc64-linux-gnu. OK to install?
>>
>> Thanks,
>> Richard
>>
>>
>> Index: gcc/wide-int.h
>> ===================================================================
>> --- gcc/wide-int.h 2014-05-02 16:28:09.561842842 +0100
>> +++ gcc/wide-int.h 2014-05-02 16:44:04.015463718 +0100
>> @@ -2046,6 +2046,8 @@ wi::sext (const T &x, unsigned int offse
>> unsigned int precision = get_precision (result);
>> WIDE_INT_REF_FOR (T) xi (x, precision);
>>
>> + gcc_checking_assert (offset != 0);
>> +
>> if (offset <= HOST_BITS_PER_WIDE_INT)
>> {
>> val[0] = sext_hwi (xi.ulow (), offset);
>> @@ -2065,6 +2067,8 @@ wi::zext (const T &x, unsigned int offse
>> unsigned int precision = get_precision (result);
>> WIDE_INT_REF_FOR (T) xi (x, precision);
>>
>> + gcc_checking_assert (offset != 0);
>> +
>> /* This is not just an optimization, it is actually required to
>> maintain canonization. */
>> if (offset >= precision)
>> @@ -2102,6 +2106,9 @@ wi::set_bit (const T &x, unsigned int bi
>> WI_UNARY_RESULT_VAR (result, val, T, x);
>> unsigned int precision = get_precision (result);
>> WIDE_INT_REF_FOR (T) xi (x, precision);
>> +
>> + gcc_checking_assert (bit < precision);
>> +
>> if (precision <= HOST_BITS_PER_WIDE_INT)
>> {
>> val[0] = xi.ulow () | ((unsigned HOST_WIDE_INT) 1 << bit);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-05-03 7:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-02 19:20 [wide-int] Add more assertions Richard Sandiford
2014-05-03 1:40 ` Kenneth Zadeck
2014-05-03 7:00 ` Richard Sandiford
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).