Re: [HACKERS] Reliance on undefined behaviour in << operator

2015-09-16 Thread k...@rice.edu
On Wed, Sep 16, 2015 at 03:57:04PM -0400, Tom Lane wrote: > Robert Haas writes: > > On Wed, Sep 16, 2015 at 3:16 AM, Craig Ringer wrote: > >> Our implementation of << is a direct wrapper around the C operator. It > >> does not check the right-hand side's value. > >> ... On x64 intel gcc linux it

Re: [HACKERS] Reliance on undefined behaviour in << operator

2015-09-16 Thread Andres Freund
On 2015-09-16 15:57:04 -0400, Tom Lane wrote: > Robert Haas writes: > > On Wed, Sep 16, 2015 at 3:16 AM, Craig Ringer wrote: > >> Our implementation of << is a direct wrapper around the C operator. It > >> does not check the right-hand side's value. > >> ... On x64 intel gcc linux it does a rotat

Re: [HACKERS] Reliance on undefined behaviour in << operator

2015-09-16 Thread Robert Haas
On Wed, Sep 16, 2015 at 3:57 PM, Tom Lane wrote: > Robert Haas writes: >> On Wed, Sep 16, 2015 at 3:16 AM, Craig Ringer wrote: >>> Our implementation of << is a direct wrapper around the C operator. It >>> does not check the right-hand side's value. >>> ... On x64 intel gcc linux it does a rotat

Re: [HACKERS] Reliance on undefined behaviour in << operator

2015-09-16 Thread Tom Lane
Robert Haas writes: > On Wed, Sep 16, 2015 at 3:16 AM, Craig Ringer wrote: >> Our implementation of << is a direct wrapper around the C operator. It >> does not check the right-hand side's value. >> ... On x64 intel gcc linux it does a rotation but that's >> not AFAIK guaranteed by anything, and

Re: [HACKERS] Reliance on undefined behaviour in << operator

2015-09-16 Thread Robert Haas
On Wed, Sep 16, 2015 at 3:16 AM, Craig Ringer wrote: > Our implementation of << is a direct wrapper around the C operator. It > does not check the right-hand side's value. > > Datum > int8shl(PG_FUNCTION_ARGS) > { > int64 arg1 = PG_GETARG_INT64(0); > int32

Re: [HACKERS] Reliance on undefined behaviour in << operator

2015-09-16 Thread Kyotaro HORIGUCHI
Hello, I don't think so many people have used shift operators with too-large or negative shift amount relying on the undetermined behavior. But if explicit definition is required, I prefer the result of a shift operation with too-large shift mount is simplly zero. And shift left with negative shif

[HACKERS] Reliance on undefined behaviour in << operator

2015-09-16 Thread Craig Ringer
Hi all Our implementation of << is a direct wrapper around the C operator. It does not check the right-hand side's value. Datum int8shl(PG_FUNCTION_ARGS) { int64 arg1 = PG_GETARG_INT64(0); int32 arg2 = PG_GETARG_INT32(1); PG_RETURN_INT64(a