Re: [RFC] overflow checks optimized away

From: Greg Stark <stark(at)mit(dot)edu>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Xi Wang <xi(dot)wang(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [RFC] overflow checks optimized away
Date: 2013-11-29 19:39:55
Message-ID: CAM-w4HPQFnmPVqgsZZvqga8ZWuWgVK1KqedAFZsQZ9BDUvP9Pw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Nov 29, 2013 at 5:21 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
>> c) I want to add regression tests that will ensure that the overflow
>> checks are all working. So far I haven't been able to catch any being
>> optimized away even with -fno-wrapv and -fstrict-overflow.
>
> This does not leave me with a warm feeling about whether this is a useful
> exercise. Maybe you need to try a different compiler?

Just as an update I did get gcc to do the wrong thing on purpose. The
only overflow check that the regression tests find missing is the one
for int8abs() ie:

*** /home/stark/src/postgresql/postgresql/src/test/regress/expected/int8.out
Wed Jul 17 19:23:02 2013
--- /home/stark/src/postgresql/postgresql/src/test/regress/results/int8.out
Fri Nov 29 14:22:31 2013
***************
*** 674,680 ****
select '9223372036854775800'::int8 % '0'::int8;
ERROR: division by zero
select abs('-9223372036854775808'::int8);
! ERROR: bigint out of range
select '9223372036854775800'::int8 + '100'::int4;
ERROR: bigint out of range
select '-9223372036854775800'::int8 - '100'::int4;
--- 674,684 ----
select '9223372036854775800'::int8 % '0'::int8;
ERROR: division by zero
select abs('-9223372036854775808'::int8);
! abs
! ----------------------
! -9223372036854775808
! (1 row)
!
select '9223372036854775800'::int8 + '100'::int4;
ERROR: bigint out of range
select '-9223372036854775800'::int8 - '100'::int4;

======================================================================

--
greg

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2013-11-29 19:58:06 Re: MultiXact truncation, startup et al.
Previous Message Alvaro Herrera 2013-11-29 19:30:08 Re: MultiXact truncation, startup et al.