Bug 33043

Summary: Miscompiled statement a[i] = (a[i]++) % x;
Product: gcc Reporter: Gregor Jasny <gjasny>
Component: cAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: alexey, algorithmus, asokumar, astier, av1474, bala, barnarr, behloul.younes, bmead15, buergel, carpman, chuchunxin, devnull, d_picco, eric.mcvicker, fuchsia.groan, gaurav_har, gcc-bugs, gcc, ggs, gjasny, j.witteveen, jandres, janis, jesser, jompo, krs, lid, lindahlb, lxg8906, mayer, mikaldaz, mike.clarkson, nakkore, nanericwang, nobs, pierre.van.de.laar_at_philips.com, qyang, ramiller, raoulgough, raphael.ribas, rglan, rjvbertin, robc, s9322036, SimonX200, smartmouse714, suan, super.aorta, svetozarmarkov, tczarnecki, vanveghel, vitaly, windows2000d, zshao
Priority: P3    
Version: 4.1.2   
Target Milestone: ---   
Host: i486-pc-linux-gnu Target: i486-pc-linux-gnu
Build: i486-pc-linux-gnu Known to work:
Known to fail: Last reconfirmed:
Attachments: Simple testcase

Description Gregor Jasny 2007-08-10 10:50:38 UTC
When the following program is compiled with gcc the output of the array-value is 1 2 3 4 5 6. Icc and cl produce the output 1 2 3 4 1 2. If the arrray is susbtituted by a simple scalar, the gcc output is 1 2 3 4 1 2, too.

I don't know if the statement if even valid and behavior-defined C code. If it's not, then gcc maybe should warn somehow.

Thanks,
 Gregor

PS: This hapens with gcc-snapshot 20070720-1, too.
Comment 1 Gregor Jasny 2007-08-10 10:51:23 UTC
Created attachment 14049 [details]
Simple testcase
Comment 2 Gregor Jasny 2007-08-10 12:02:07 UTC
I've found:
http://c-faq.com/expr/seqpoints.html

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