https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82274
Bug ID: 82274
Summary: __builtin_mul_overflow fails to detect overflow for
int64_t when compiled with -m32
Product: gcc
Version: 5.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mats at mozilla dot com
Target Milestone: ---
The result from this test should be:
# g++ -std=c++11 bug.cpp && ./a.out
SUCCESS: overflow detected
Result is 0
but when compiled with -m32 it fails to detect the overflow:
# g++ -m32 -std=c++11 bug.cpp && ./a.out
ERROR: failed to detect overflow!
Result is 0
However, adding -O makes it work again:
# g++ -O -m32 -std=c++11 bug.cpp && ./a.out
SUCCESS: overflow detected
Result is 0
# g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
(same results with g++ (GCC) 7.2.0)