This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

optimization/5159: ptr[i] = ptr[++i]; // works differently with malloc() and -O



>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);
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]