From: | Andres Freund <andres(at)anarazel(dot)de> |
---|---|
To: | pgsql-hackers(at)lists(dot)postgresql(dot)org,Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>,Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>,Peter Geoghegan <pg(at)bowt(dot)ie>,Noah Misch <noah(at)leadboat(dot)com>,PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Clang UndefinedBehaviorSanitize (Postgres14) Detected undefined-behavior |
Date: | 2020-08-31 18:42:21 |
Message-ID: | 8B39F978-F97D-4C7C-B6EF-2A399FCF0E1D@anarazel.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi,
On August 31, 2020 11:08:49 AM PDT, Ranier Vilela <ranier(dot)vf(at)gmail(dot)com> wrote:
>Em seg., 31 de ago. de 2020 às 14:43, Ranier Vilela
><ranier(dot)vf(at)gmail(dot)com>
>escreveu:
>
>> Em seg., 31 de ago. de 2020 às 14:00, Alvaro Herrera <
>> alvherre(at)2ndquadrant(dot)com> escreveu:
>>
>>> On 2020-Aug-31, Ranier Vilela wrote:
>>>
>>> > More troubles with undefined-behavior.
>>> >
>>> > This type of code can leaves overflow:
>>> > var = (cast) (expression);
>>> > diff = (int32) (id1 - id2);
>>> >
>>> > See:
>>> > diff64 = ((long int) d1 - (long int) d2);
>>> > diff64=-4294901760
>>>
>>> Did you compile this with gcc -fwrapv?
>>>
>> gcc 10.2 -O2 -fwrapv
>> bool test1()
>> {
>> unsigned int d1 = 3;
>> unsigned int d2 = 4294901763;
>> long int diff64 = 0;
>>
>> diff64 = ((long int) d1 - (long int) d2);
>>
>> return (diff64 < 0);
>> }
>>
>> output:
>> mov eax, 1
>> ret
>>
>> What is a workaround for msvc 2019 (64 bits) and clang 64 bits
>(linux)?
>> transam.c:311:22: runtime error: unsigned integer overflow: 3 -
>4294901763
>> cannot be represented in type 'unsigned int'
Unsigned integer overflow is well defined in the standard. So I don't understand what this is purporting to warn about.
Andres
Regards,
Andres
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
From | Date | Subject | |
---|---|---|---|
Next Message | Thomas Munro | 2020-08-31 19:21:57 | Re: Boundary value check in lazy_tid_reaped() |
Previous Message | Andres Freund | 2020-08-31 18:38:11 | Re: LogwrtResult contended spinlock |