Attempt to fix breakage caused by signed integer conversion patch.

Use INT_MIN rather than INT32_MIN as we do elsewhere in the code, and
try to work around nonexistence of INT64_MIN if necessary.  Adjust the
new regression tests to something hopefully saner, per observation by
Tom Lane.
This commit is contained in:
Robert Haas 2010-11-20 01:07:04 -05:00
parent b58c25055e
commit 815810ed31
7 changed files with 43 additions and 33 deletions

View File

@ -18,6 +18,16 @@
#include <limits.h>
#include <ctype.h>
/*
* Defining INT64_MIN as -9223372036854775808LL may not work; the compiler's
* tokenizer may see - as a separate token and then be unable to view
* 9223372036854775808 as a number. This is the standard workaround for that
* problem.
*/
#ifndef INT64_MIN
#define INT64_MIN (-9223372036854775807LL - 1)
#endif
#include "utils/builtins.h"
/*
@ -136,7 +146,7 @@ pg_ltoa(int32 value, char *a)
* Avoid problems with the most negative integer not being representable
* as a positive integer.
*/
if (value == INT32_MIN)
if (value == INT_MIN)
{
memcpy(a, "-2147483648", 12);
return;

View File

@ -243,15 +243,15 @@ SELECT '' AS five, i.f1, i.f1 / int4 '2' AS x FROM INT2_TBL i;
(5 rows)
-- corner cases
SELECT (1<<15-1)::int2::text;
text
-------
16384
(1 row)
SELECT (-1<<15)::int2::text;
SELECT (-1::int2<<15)::text;
text
--------
-32768
(1 row)
SELECT ((-1::int2<<15)+1)::text;
text
--------
-32767
(1 row)

View File

@ -329,16 +329,16 @@ SELECT (2 + 2) / 2 AS two;
2
(1 row)
-- corner cases
SELECT (1<<31-1)::int4::text;
text
------------
1073741824
(1 row)
SELECT (1<<31)::int4::text;
-- corner case
SELECT (-1::int4<<31)::text;
text
-------------
-2147483648
(1 row)
SELECT ((-1::int4<<31)+1)::text;
text
-------------
-2147483647
(1 row)

View File

@ -802,16 +802,16 @@ SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::in
4567890123456799
(6 rows)
-- corner cases
SELECT (1<<63-1)::int8::text;
text
------------
1073741824
-- corner case
SELECT (-1::int8<<63)::text;
text
----------------------
-9223372036854775808
(1 row)
SELECT (1<<63)::int8::text;
text
-------------
-2147483648
SELECT ((-1::int8<<63)+1)::text;
text
----------------------
-9223372036854775807
(1 row)

View File

@ -85,5 +85,5 @@ SELECT '' AS five, i.f1, i.f1 / int2 '2' AS x FROM INT2_TBL i;
SELECT '' AS five, i.f1, i.f1 / int4 '2' AS x FROM INT2_TBL i;
-- corner cases
SELECT (1<<15-1)::int2::text;
SELECT (-1<<15)::int2::text;
SELECT (-1::int2<<15)::text;
SELECT ((-1::int2<<15)+1)::text;

View File

@ -124,6 +124,6 @@ SELECT 2 + 2 / 2 AS three;
SELECT (2 + 2) / 2 AS two;
-- corner cases
SELECT (1<<31-1)::int4::text;
SELECT (1<<31)::int4::text;
-- corner case
SELECT (-1::int4<<31)::text;
SELECT ((-1::int4<<31)+1)::text;

View File

@ -191,6 +191,6 @@ SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::in
SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::int8, 0);
SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::int8, 2);
-- corner cases
SELECT (1<<63-1)::int8::text;
SELECT (1<<63)::int8::text;
-- corner case
SELECT (-1::int8<<63)::text;
SELECT ((-1::int8<<63)+1)::text;