$ gcc-8 -x c - <<< 'void main() { int x=0x80000000; printf("%d,%d,%d,%d\n",x,-x,(x-1),x<(x-1)); }' $ ./a.out -2147483648,-2147483648,2147483647,0 Должно быть -2147483648,-2147483648,2147483647,1
На x86_64 это тоже вылезает. $ gcc-8 -x c - <<< 'void main() { int x=0x80000000; > printf("%d,%d,%d,%d\n",x,-x,(x-1),x<(x-1)); }' <stdin>: In function ‘main’: <stdin>:2:1: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration] <stdin>:2:1: warning: incompatible implicit declaration of built-in function ‘printf’ <stdin>:2:1: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’ $ ./a.out -2147483648,-2147483648,2147483647,0 $ gcc-7 -x c - <<< 'void main() { int x=0x80000000; printf("%d,%d,%d,%d\n",x,-x,(x-1),x<(x-1)); }' <stdin>: In function ‘main’: <stdin>:2:1: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration] <stdin>:2:1: warning: incompatible implicit declaration of built-in function ‘printf’ <stdin>:2:1: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’ $ ./a.out -2147483648,-2147483648,2147483647,1
Не похоже чтобы это от архитектуры зависело -- на aarch64 и ppc64le результат тот же.
А это точно не ub?
сравните с -fno-strict-overflow :)
(В ответ на комментарий №4) > сравните с -fno-strict-overflow :) Скорее с -fwrapv Вот бага в Питоне соответствующая, закрыта как not a bug: https://bugs.python.org/issue34096
(In reply to comment #5) > (В ответ на комментарий №4) > > сравните с -fno-strict-overflow :) > > Скорее с -fwrapv Между -fno-strict-overflow и -fwrapv есть очень тесная связь. :) Вопрос в том, какое значение по умолчанию мы хотим.
Конкретно при сборке Python эта опция выставляется явно, но в нашем пакете она перебивалась, наша вина.
Это изменение в gcc было документировано, см. https://gcc.gnu.org/gcc-8/changes.html: -fno-strict-overflow is now mapped to -fwrapv -fwrapv-pointer and signed integer overflow is now undefined by default at all optimization levels. Если нас не устраивает новое документированное поведение gcc, можно обсудить, что с этим делать, но не здесь.