Thread (31 messages) 31 messages, 10 authors, 2018-11-05

Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

From: Peter Zijlstra <peterz@infradead.org>
Date: 2018-11-05 14:26:17
Also in: linux-mips, linux-nfs, linuxppc-dev, lkml

On Fri, Nov 02, 2018 at 07:19:15PM +0300, Andrey Ryabinin wrote:
UBSAN warns about signed overflows despite -fno-strict-overflow if gcc version is < 8.
I have learned recently that UBSAN in GCC 8 ignores signed overflows if -fno-strict-overflow of fwrapv is used.

$ cat signed_overflow.c 
#include <stdio.h>

__attribute__((noinline))
int foo(int a, int b)
{
        return a+b;
 s/+/<</
}

int main(void)
{
        int a = 0x7fffffff;
        int b = 2;
        printf("%d\n", foo(a,b));
        return 0;
}
It also seem to affect 'shift':

peterz@hirez:~/tmp$ gcc -fsanitize=signed-integer-overflow,shift overflow.c ; ./a.out
overflow.c:6:11: runtime error: left shift of 2147483647 by 2 places cannot be represented in type 'int'
-4
peterz@hirez:~/tmp$ gcc -fsanitize=signed-integer-overflow,shift -fwrapv overflow.c ; ./a.out
-4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help