gcc generates incorrect code with -Os
Krzysztof Halasa
khc@pm.waw.pl
Tue Dec 6 15:50:00 GMT 2005
Hi,
gcc-4.0.1-4.fc4
gcc-4.0.2-8.fc4 (4.0.2 20051125 (Red Hat 4.0.2-8))
i386
gcc -W -Wall -Os test.c -o test -Werror && ./test
array: 1 2
array: 1 2
gcc -W -Wall -O2 test.c -o test -Werror && ./test
array: 1 2
array: 2 3
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=173764
#include <stdio.h>
void test_it(int *array)
{
int i;
for (i = 0; i < 2; i++) {
int value = array[i];
if (i != 1000 && i != 1001)
array[i] = value + 1;
}
}
int main(void)
{
int array[2] = {1, 2};
printf("array: %i %i\n", array[0], array[1]);
test_it(array);
printf("array: %i %i\n", array[0], array[1]);
return 0;
}
--
Krzysztof Halasa
More information about the Gcc
mailing list