GCC Bugzilla has been upgraded from version 4.4.9 to 5.0rc3. If you see any problem, please report it to bug 64968.
Bug 1570 - gcc 2.8.1 has autoincrement bug
Summary: gcc 2.8.1 has autoincrement bug
Status: RESOLVED DUPLICATE of bug 11751
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2001-01-05 17:16 UTC by rglan
Modified: 2005-11-10 03:17 UTC (History)
40 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description rglan 2001-01-05 17:16:01 UTC
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
Comment 1 rglan 2001-01-05 17:16:01 UTC
Fix:
Make autoincrements work at all times.
Comment 2 Alexandre Oliva 2001-01-06 14:26:27 UTC
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
Comment 3 Joseph S. Myers 2001-01-14 04:03:52 UTC
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)
Comment 4 Joseph S. Myers 2001-01-14 12:03:52 UTC
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
Comment 5 Andrew Pinski 2005-11-10 03:17:16 UTC
Reopening to ...
Comment 6 Andrew Pinski 2005-11-10 03:17:31 UTC
Close as a dup of bug 11751.

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