Bug 8175 - different behaviour with different optimization levels
Summary: different behaviour with different optimization levels
Status: RESOLVED DUPLICATE of bug 11751
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 2.95.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-10-09 08:36 UTC by pierre.van.de.laar_at_philips.com
Modified: 2005-11-10 03:48 UTC (History)
42 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description pierre.van.de.laar_at_philips.com 2002-10-09 08:36:01 UTC
The following (stupid, I admit) code is treated differently under different optimalizations (no warning or error is made)

#include <stdio.h>
int main(int argc, char * argv[])
{
	int i;
	/* use argc */
	i = argc;
	if (i++ == i++) 
	{
		printf("true %d\n",i);
	}
	else
	{
		printf("false %d\n",i);
	}
    return 0;
}
laarp@mollis [199] > gcc -Wall -O0 test.c
laarp@mollis [200] > a.out               
true 2
laarp@mollis [201] > gcc -Wall -O6 test.c
laarp@mollis [202] > a.out               
false 3

Note: This piece of code violates: an object shall have its stored value modified at most once by the evaluation of an expression
(Committee Draft -- August 3, 1998, WG14/N843 
paragraph 6.5 Expressions)
I don't know if it is still part of the the official release.

Release:
gcc version 2.95.3 20010315 (release)

Environment:
unix

How-To-Repeat:
Just compile the code and see for yourself!
Comment 1 pierre.van.de.laar_at_philips.com 2002-10-09 08:36:01 UTC
Fix:
Generate at least a warning or always have the same behaviour.
Comment 2 Richard Henderson 2002-10-11 16:19:04 UTC
State-Changed-From-To: open->closed
State-Changed-Why: Not a bug.  Undefined behaviour: two modifications with
    no sequence point.
Comment 3 Andrew Pinski 2005-11-10 03:47:57 UTC
Reopening to ...
Comment 4 Andrew Pinski 2005-11-10 03:48:21 UTC
a dup of bug 11751.

*** This bug has been marked as a duplicate of 11751 ***