pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #17167: UndefinedBehaviorSanitizer: invalid-shift-exponent while running int4shr/int4shl
2+ messages / 2 participants
[nested] [flat]

* BUG #17167: UndefinedBehaviorSanitizer: invalid-shift-exponent while running int4shr/int4shl
@ 2021-08-30 09:02  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2021-08-30 09:02 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: ssubhrajyoti@google.com

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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #17167: UndefinedBehaviorSanitizer: invalid-shift-exponent while running int4shr/int4shl
@ 2021-08-30 12:00  Alexander Lakhin <exclusion@gmail.com>
  parent: PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Alexander Lakhin @ 2021-08-30 12:00 UTC (permalink / raw)
  To: ssubhrajyoti@google.com, pgsql-bugs@lists.postgresql.org, PG Bug reporting form <noreply@postgresql.org>

Hello Subhrajyoti,

30.08.2021 12:02, PG Bug reporting form wrote:
> Bug reference:      17167
>
> 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 like a duplicate of #16790:
https://www.postgresql.org/message-id/flat/16790-c2a81c92a8776c5b%40postgresql.org

Best regards,
Alexander





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2021-08-30 12:00 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-08-30 09:02 BUG #17167: UndefinedBehaviorSanitizer: invalid-shift-exponent while running int4shr/int4shl PG Bug reporting form <noreply@postgresql.org>
2021-08-30 12:00 ` Alexander Lakhin <exclusion@gmail.com>

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