User account creation filtered due to spam.

Bug 8175

Summary: different behaviour with different optimization levels
Product: gcc Reporter:
Component: rtl-optimizationAssignee: Not yet assigned to anyone <unassigned>
Severity: normal CC: algorithmus, arminu, asokumar, bala, barnarr, bmead15, buergel, carpman, ceniza666, chuchunxin, devnull, d_picco, eric.mcvicker, gaurav_har, gcc-bugs, gcc, ggs, horsh, jandres, janis, krs, lid, lindahlb, lxg8906, mikaldaz, nakkore,, qyang, raoulgough, rglan, rjvbertin, robc, rth, s9322036, smartmouse714, suan, super.aorta, svetozarmarkov, tczarnecki, vanveghel, work, zshao
Priority: P3    
Version: 2.95.3   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description 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);
		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.

gcc version 2.95.3 20010315 (release)


Just compile the code and see for yourself!
Comment 1 2002-10-09 08:36:01 UTC
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 ***