BUG #16790: Integer overflow not detected with << - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #16790: Integer overflow not detected with <<
Date
Msg-id 16790-c2a81c92a8776c5b@postgresql.org
Whole thread Raw
Responses Re: BUG #16790: Integer overflow not detected with <<
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      16790
Logged by:          Alexander Lakhin
Email address:      exclusion@gmail.com
PostgreSQL version: 13.1
Operating system:   Ubuntu 20.04
Description:

It seems that the bitwise shift left operator ignores overflow:
SELECT -1::int4<<32;
-1
But:
SELECT (-1::int4<<31) * 2;
ERROR:  integer out of range

Is this an expected behavior (a kind of UB)? It's not like an arithmetic
shift. (The semantic of '1::int4<<-1' is questionable too.)


pgsql-bugs by date:

Previous
From: Michael Paquier
Date:
Subject: Re: CREATE INDEX CONCURRENTLY does not index prepared xact's data
Next
From: Tom Lane
Date:
Subject: Re: BUG #16790: Integer overflow not detected with <<