pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: ssubhrajyoti@google.com
Subject: BUG #17167: UndefinedBehaviorSanitizer: invalid-shift-exponent while running int4shr/int4shl
Date: Mon, 30 Aug 2021 09:02:36 +0000
Message-ID: <17167-028026e4ca333817@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      17167
Logged by:          Subhrajyoti Senapati
Email address:      ssubhrajyoti@google.com
PostgreSQL version: 12.8
Operating system:   Linux
Description:        

Hi,

When executing in an asan instrumented build,
```
postgres=> SELECT int4shr(10, -1);
```
throws an error `runtime error: shift exponent 32 is too large for 32-bit
type 'int32' (aka 'int')`

This seems to be coming from this line:
https://github.com/postgres/postgres/blob/c30f54ad732ca5c8762bb68bbe0f51de9137dd72/src/backend/utils...

While browsing, i found this link:
https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+numb...,
according to which shifting by negative number of bits or >= bits in the
operand is classified as a undefined behaviour.

Few experiments i tried:
```
postgres=> SELECT int4shr(10, 1);
 int4shr 
---------
       5
(1 row)

postgres=> SELECT int4shr(10, -1);
 int4shr 
---------
       0
(1 row)

postgres=> SELECT int4shr(10, -2);
 int4shr 
---------
       0
(1 row)
```

I am not sure if it's a bug or expected behaviour.

Thanks,
Subhrajyoti



view thread (2+ messages)  latest in thread

Message-ID: <17167-028026e4ca333817@postgresql.org>
Permalink:  ../17167-028026e4ca333817@postgresql.org/
Also on:    postgresql.org/message-id/17167-028026e4ca333817@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, ssubhrajyoti@google.com
  Subject: Re: BUG #17167: UndefinedBehaviorSanitizer: invalid-shift-exponent while running int4shr/int4shl
  In-Reply-To: <17167-028026e4ca333817@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox