This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
optimization/5159: ptr[i] = ptr[++i]; // works differently with malloc() and -O
- From: robc at free dot fr
- To: gcc-gnats at gcc dot gnu dot org
- Date: 18 Dec 2001 22:52:21 -0000
- Subject: optimization/5159: ptr[i] = ptr[++i]; // works differently with malloc() and -O
- Reply-to: robc at free dot fr
>Number: 5159
>Category: optimization
>Synopsis: ptr[i] = ptr[++i]; // works differently with malloc() and -O
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Tue Dec 18 14:56:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: RobC
>Release: gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
Linux 2.2.19, Pentium II
>Description:
ptr[i] = ptr[++i];
when ptr is a pointer and compiled with -O then it behaves differently.
>How-To-Repeat:
compile with "gcc -O"
>Fix:
ptr[i] = ptr[i+1];
i++;
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="test.c"
Content-Disposition: inline; filename="test.c"
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i=0;
int *pos = malloc(sizeof(int) * 2);
pos[0] = 0;
pos[1] = 1;
pos[i] = pos[++i];
printf("%i %i\n", pos[0], pos[1]);
return(0);
}