A fix is available
APAR status
Closed as program error.
Error description
Compiler generates incorrect operand value for post decrement/increment operations in while/for/if statements. ___________________ Test Case for while statement: int main() { int id=6; int sum=0; while(id--) { for (int i=0; i<id; i++) sum+=i; printf("sum=%d, id=%d\n", sum, id); } } Expected output: sum=10, id=5 sum=16, id=4 sum=19, id=3 sum=20, id=2 sum=20, id=1 sum=20, id=0 Actual output: sum=15, id=5 sum=25, id=4 sum=31, id=3 sum=34, id=2 sum=35, id=1 sum=35, id=0 __________________________ Testcase for if statement. int main() { int id=6; int sum=0; if(id--) { for (int i=0; i<id; i++) sum+=i; printf("sum=%d, id=%d\n", sum, id); } } Expected output: sum=10, id=5 Actual output: sum=15, id=5 ___________________________________________
Local fix
Avoid using whie(id--) or if (id--) statements. Or printf id's value before comparison statement in the for loop.
Problem summary
Compiler incorrectly treats postfix increment/decrement operations in while and for loop's conditional statement as compiler generated statement and generates incorrect operand value.
Problem conclusion
Fixed the optimizatin process for postfix increment/decrement operations in while and for loop's conditional statement by creating a querry function to check if a statement is truely a compiler generated statement. Also fix a similar problem in the if-else statement.
Temporary fix
Comments
APAR Information
APAR number
LI71622
Reported component name
XL C/C++ RHEL4
Reported component ID
5724K7720
Reported release
701
Status
CLOSED PER
PE
NoPE
HIPER
NoHIPER
Special Attention
NoSpecatt
Submitted date
2006-10-25
Closed date
2006-10-25
Last modified date
2006-10-25
APAR is sysrouted FROM one or more of the following:
APAR is sysrouted TO one or more of the following:
Fix information
Fixed component name
XL C/C++ RHEL4
Fixed component ID
5724K7720
Applicable component levels
R701 PSN IY81172
UP06/09/13
[{"Business Unit":{"code":"BU054","label":"Systems w\/TPS"},"Product":{"code":"SSJT9L","label":"XL C\/C++"},"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"7.0.1","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}}]
Document Information
Modified date:
16 October 2021