When useing an index into an array, and autoincrementing the index, the compiler doesn't generate the code to autoincrement the index. =============Code sample====================== #include <stdio.h> unsigned long Point; unsigned char buf[8]; unsigned char val; int main(void) { Point = 0; buf[0] = 1; buf[1] = 0; buf[2] = 1; val = (buf[Point++] << 2) | (buf[Point++] << 1) | (buf[Point++]); printf("val = %x, Point = %x\n",val,Point); return(0); } =============end of sample=================== produces an output of; val=7, Point=1; I understand that the expression isn't really legal since it involves autoincrementing an index in a certain order that isn't guarenteed by any compiler, but it should at least increment the index pointer as it evaluates the expression. Release: gcc 2.8.1 Environment: Irix64 release 6.5 How-To-Repeat: Compile small source code. Run it. Output should be; val=5, Point=3 where val is there bits ORed together and Point is the array index pointer
Fix: Make autoincrements work at all times.
From: Alexandre Oliva <aoliva@redhat.com> To: rglan@engr.sgi.com Cc: gcc-gnats@gcc.gnu.org Subject: Re: c/1570: gcc 2.8.1 has autoincrement bug Date: 06 Jan 2001 14:26:27 -0200 On Jan 5, 2001, rglan@engr.sgi.com wrote: > val = (buf[Point++] << 2) | (buf[Point++] << 1) | (buf[Point++]); > I understand that the expression isn't really legal since > it involves autoincrementing an index in a certain order > that isn't guarenteed by any compiler, but it should at > least increment the index pointer as it evaluates the > expression. Your understanding is wrong. The program invokes undefined behavior, which means anything at all can happen. -- Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/ Red Hat GCC Developer aoliva@{cygnus.com, redhat.com} CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org} Free Software Evangelist *Please* write to mailing lists, not to me
State-Changed-From-To: open->closed State-Changed-Why: Not a bug: this code involves undefined behavior. CVS GCC will tell you (with -Wall): t.c: In function `main': t.c:12: warning: operation on `Point' may be undefined t.c:12: warning: operation on `Point' may be undefined t.c:13: warning: unsigned int format, long unsigned int arg (arg 3)
From: jsm28@gcc.gnu.org To: gcc-gnats@gcc.gnu.org, jsm28@cam.ac.uk, nobody@gcc.gnu.org, rglan@engr.sgi.com Cc: Subject: Re: c/1570 Date: 14 Jan 2001 12:03:52 -0000 Synopsis: gcc 2.8.1 has autoincrement bug State-Changed-From-To: open->closed State-Changed-By: jsm28 State-Changed-When: Sun Jan 14 04:03:52 2001 State-Changed-Why: Not a bug: this code involves undefined behavior. CVS GCC will tell you (with -Wall): t.c: In function `main': t.c:12: warning: operation on `Point' may be undefined t.c:12: warning: operation on `Point' may be undefined t.c:13: warning: unsigned int format, long unsigned int arg (arg 3) http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=1570&database=gcc
Reopening to ...
Close as a dup of bug 11751. *** This bug has been marked as a duplicate of 11751 ***