Message144071
I'm not sure if this is a good idea: I wonder if it would be an option
to check for overflow behavior at the bottom of ./configure and print a
warning. The patch appears to work for gcc, clang and suncc. It would
have caught the problem in #12973.
The Intel compiler is the odd one here. Even with -O0 this particular
overflow is undefined, but I can't remember seeing the specific
test failures from #12973. So the drawback is that the patch might
give false positives.
$ cat overflow_is_defined.c
#include <limits.h>
int overflow_is_defined(int x) {
if (x + 1000 < x)
return 0;
return 1;
}
int main() {
return overflow_is_defined(INT_MAX);
}
gcc-4.4.3
=========
$ gcc -Wall -W -O0 -o overflow_is_defined overflow_is_defined.c
$ ./overflow_is_defined || echo "undefined"
$ gcc -Wall -W -O2 -o overflow_is_defined overflow_is_defined.c
overflow_is_defined.c: In function ‘overflow_is_defined’:
overflow_is_defined.c:3: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false
$ ./overflow_is_defined || echo "undefined"
undefined
$ gcc -Wall -W -O2 -fwrapv -o overflow_is_defined overflow_is_defined.c
$ ./overflow_is_defined || echo "undefined"
$
clang-3.0
=========
$ clang -Wall -W -O0 -o overflow_is_defined overflow_is_defined.c
$ ./overflow_is_defined || echo "undefined"
$ clang -Wall -W -O2 -o overflow_is_defined overflow_is_defined.c
$ ./overflow_is_defined || echo "undefined"
undefined
$ clang -Wall -W -fwrapv -O2 -o overflow_is_defined overflow_is_defined.c
$ ./overflow_is_defined || echo "undefined"
$
suncc-12.2
==========
$ suncc -o overflow_is_defined overflow_is_defined.c
$ ./overflow_is_defined || echo "undefined"
$ suncc -O2 -o overflow_is_defined overflow_is_defined.c
$ ./overflow_is_defined || echo "undefined"
$
icc-12.0.0
==========
$ icc -Wall -O0 -o overflow_is_defined overflow_is_defined.c
$ ./overflow_is_defined || echo "undefined"
undefined
$ icc -Wall -O2 -o overflow_is_defined overflow_is_defined.c
$ ./overflow_is_defined || echo "undefined"
undefined
$ |
|
Date |
User |
Action |
Args |
2011-09-15 09:34:37 | skrah | set | recipients:
+ skrah |
2011-09-15 09:34:37 | skrah | set | messageid: <1316079277.71.0.960663177072.issue12985@psf.upfronthosting.co.za> |
2011-09-15 09:34:37 | skrah | link | issue12985 messages |
2011-09-15 09:34:36 | skrah | create | |
|