User account creation filtered due to spam.

Bug 5159 - ptr[i] = ptr[++i]; // works differently with malloc() and -O
Summary: ptr[i] = ptr[++i]; // works differently with malloc() and -O
Status: RESOLVED DUPLICATE of bug 11751
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 2.95.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2001-12-18 14:56 UTC by robc
Modified: 2005-04-20 02:56 UTC (History)
2 users (show)

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


Attachments
test.c (145 bytes, application/octet-stream)
2003-05-21 15:17 UTC, robc
Details

Note You need to log in before you can comment on or make changes to this bug.
Description robc 2001-12-18 14:56:00 UTC
ptr[i] = ptr[++i];
when ptr is a pointer and compiled with -O then it behaves differently.

Release:
gcc version 2.95.2 19991024 (release)

Environment:
Linux 2.2.19, Pentium II

How-To-Repeat:
compile with "gcc -O"
Comment 1 robc 2001-12-18 14:56:00 UTC
Fix:
ptr[i] = ptr[i+1];
i++;
Comment 2 Neil Booth 2001-12-18 15:22:36 UTC
State-Changed-From-To: open->closed
State-Changed-Why: Not a bug - you should read up on sequence points.  Basically, multiple reads of a variable (i) modified between sequence points is undefined.  Your code falls into this category.  So,
    
    ptr[i] = ptr[++i];
    
    is fundamentally always meaningless.
Comment 3 Andrew Pinski 2005-04-20 02:56:04 UTC
Reopening to ...
Comment 4 Andrew Pinski 2005-04-20 02:56:26 UTC
Mark as a dup of bug 11751.

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