optimization/8175: different behaviour with different optimization levels

Pierre.van.de.Laar_AT_Philips.com@sources.redhat.com Pierre.van.de.Laar_AT_Philips.com@sources.redhat.com
Wed Oct 9 08:36:00 GMT 2002


>Number:         8175
>Category:       optimization
>Synopsis:       different behaviour with different optimization levels
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Oct 09 08:36:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Pierre.van.de.Laar_AT_Philips.com
>Release:        gcc version 2.95.3 20010315 (release)
>Organization:
>Environment:
unix
>Description:
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.
>How-To-Repeat:
Just compile the code and see for yourself!
>Fix:
Generate at least a warning or always have the same behaviour.
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list