This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
optimization/8175: different behaviour with different optimization levels
- From: Pierre dot van dot de dot Laar_AT_Philips dot com at sources dot redhat dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: 9 Oct 2002 15:30:53 -0000
- Subject: optimization/8175: different behaviour with different optimization levels
- Reply-to: Pierre dot van dot de dot Laar_AT_Philips dot com at sources dot redhat dot com
>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: