Improve handling of INT_MIN / -1 and related cases.
Tom Lane <tgl@sss.pgh.pa.us>
Improve handling of INT_MIN / -1 and related cases. Some platforms throw an exception for this division, rather than returning a necessarily-overflowed result. Since we were testing for overflow after the fact, an exception isn't nice. We can avoid the problem by treating division by -1 as negation. Add some regression tests so that we'll find out if any compilers try to optimize away the overflow check conditions. Back-patch of commit 1f7cb5c30983752ff8de833de30afcaee63536d0. Per discussion with Xi Wang, though this is different from the patch he submitted.
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/utils/adt/int8.c | modified | +59 −31 |
| src/backend/utils/adt/int.c | modified | +56 −52 |
| src/test/regress/expected/int2.out | modified | +11 −0 |
| src/test/regress/expected/int4.out | modified | +21 −0 |
| src/test/regress/expected/int8-exp-three-digits.out | modified | +31 −0 |
| src/test/regress/expected/int8.out | modified | +31 −0 |
| src/test/regress/sql/int2.sql | modified | +5 −0 |
| src/test/regress/sql/int4.sql | modified | +8 −0 |
| src/test/regress/sql/int8.sql | modified | +11 −0 |