in reply to Re^2: Why does $Config{ccflags} include "-fwrapv" on many gcc builds of perl ?
in thread Why does $Config{ccflags} include "-fwrapv" on many gcc builds of perl ?
-fwrapv gives implementation defined behaviour for wrapping variables but not constants.
#include <limits.h> #include <stdio.h> int main() { printf(" LONG_MIN %ld\n", LONG_MIN); printf(" LONG_MAX %ld\n", LONG_MAX); printf("-LONG_MAX %ld\n", -LONG_MIN); // line 9 long lval = LONG_MIN; lval = lval * -1; // this is okay with -fwrapv printf("wrap lval %ld\n", lval); }
$ gcc -Wall -Wextra -Woverflow -fwrapv -fsanitize=undefined t.c -o t & +& ./t t.c: In function ‘main’: t.c:9:31: warning: integer overflow in expression ‘-922337203685477580 +8’ of type ‘long int’ results in ‘-9223372036854775808’ [-Woverflow] 9 | printf("-LONG_MAX %ld\n", -LONG_MIN); // line 9 | ^ LONG_MIN -9223372036854775808 LONG_MAX 9223372036854775807 -LONG_MAX -9223372036854775808 wrap lval 9223372036854775807
I see that the patch fixes it by changing to unsigned int so it seems the wrapping is irrelevant there.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Why does $Config{ccflags} include "-fwrapv" on many gcc builds of perl ?
by syphilis (Archbishop) on Apr 24, 2021 at 01:04 UTC |