Red Hat Bugzilla – Bug 188649
optimization changes expression semantics
Last modified: 2007-11-30 17:11:30 EST
Description of problem:
Compiling the attached test case with optimization causes the while loop to exit
after only one iteration, rather than 81 iterations. Compiling without
optimization uses the proper number of iteration. Additionally, the subsequent
assert on the negative loop condition also "succeeds" despite the fact that the
subsequent, semantically equivalent, assertion fails. Printing the loop
condition also shows that it is still true, despite the loop having exited.
While the code prior to the loop involves some odd casts, it's all standard C
and the loop itself is purely standard C, requiring only comparisons between
pointers that point to elements of the same array. This is particularly bad as
this test case was adapted from the python integer block allocator and causes it
to allocate a block of 82 ints, but only use one of them leading to huge memory
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. gcc -O test_gcc.c -o test_gcc
3. Abort on assertion that should be true
The loop is executed once and exits while the guard condition is true.
The loop is executed 81 times, and only exits once the guard condition is false.
Created attachment 127643 [details]
Test case demonstrating gcc optimization bug
Fixed in gcc-4.1.0-7 in rawhide.
Jakub -- any chance of pushing the fix into fc5-updates so we can build an