[Bug c/60527] New: Incorrectly removed if statement while doing int arithmetics
nicklas.ekstrand at sonymobile dot com
gcc-bugzilla@gcc.gnu.org
Fri Mar 14 15:51:00 GMT 2014
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60527
Bug ID: 60527
Summary: Incorrectly removed if statement while doing int
arithmetics
Product: gcc
Version: 4.6.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: nicklas.ekstrand at sonymobile dot com
Created attachment 32349
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32349&action=edit
Test program modtest.c
In the following code:
static int getZ() {
int tmp;
Z = Z * A + B;
tmp = Z;
if (tmp == INT_MIN)
tmp++;
if (tmp < 0)
tmp = -tmp;
return tmp % MEMSIZE;
}
The if-statement tmp==INT_MIN is optimized away when using -O2 or higher, e.g.,
$ gcc -Wall -Wextra -g -O2 modtest.c -o pc_modtest -lrt
$ ./pc_modtest
arr=0x7fc1608be010
i=0 A=945 B=411
z1=231029 z2=-7483648
Segmentation fault
When using -O0 the problem doesn't happen and the program will not cause a
segmentation fault.
More information about the Gcc-bugs
mailing list