Bug 188649

Summary: optimization changes expression semantics
Product: [Fedora] Fedora Reporter: Shahms E. King <shahms>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED RAWHIDE QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 5CC: katzj
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: 4.1.0-7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2006-04-12 08:53:55 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 188327    
Attachments:
Description Flags
Test case demonstrating gcc optimization bug none

Description Shahms E. King 2006-04-12 00:10:58 UTC
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
leaks.


Version-Release number of selected component (if applicable):
gcc-4.1.0-3

How reproducible:
Always

Steps to Reproduce:
1. gcc -O test_gcc.c -o test_gcc
2../test_gcc
3. Abort on assertion that should be true 
  
Actual results:
The loop is executed once and exits while the guard condition is true.

Expected results:
The loop is executed 81 times, and only exits once the guard condition is false.


Additional info:

Comment 1 Shahms E. King 2006-04-12 00:10:58 UTC
Created attachment 127643 [details]
Test case demonstrating gcc optimization bug

Comment 2 Jakub Jelinek 2006-04-12 08:53:55 UTC
Fixed in gcc-4.1.0-7 in rawhide.

Comment 3 Jeremy Katz 2006-04-26 17:01:21 UTC
Jakub -- any chance of pushing the fix into fc5-updates so we can build an
updated python?