[Bug target/49419] New: [4.6/4.7 regression] gcc -O2 miscompiles gp2c

doko at ubuntu dot com gcc-bugzilla@gcc.gnu.org
Wed Jun 15 11:11:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49419

           Summary: [4.6/4.7 regression] gcc -O2 miscompiles gp2c
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: doko@ubuntu.com


[forwarded from http://bugs.debian.org/630567]

fails with -O2/-O3, works with -O1/-Os with 20110611 4.6 branch, 20110531
trunk, apparently on {powerpc,mips,mipsel,s390}-linux.

gcc-4.6 miscompiles gp2c on several platforms including powerpc, see 
https://buildd.debian.org/status/package.php?p=gp2c

On powerpc (32 bit):
The function 'listostack' in src/utils.c is miscompiled with -O2.
Please find a testcase.

gcc-4.6 -O2 -Wall gccbug.c -o gccbug && ./gccbug
zsh: segmentation fault  ./gccbug
gcc-4.6 -O1 -Wall gccbug.c -o gccbug && ./gccbug
nb=2
0: 1
1: 2


#include <stdio.h>
#include <stdlib.h>

typedef struct
{
  enum {LEAF=0, NODE=1} f;            /*node function*/
  int x;                              /*node left child*/
  int y;                              /*node right child*/
} node; 

node *tree;

int listtostack(int n, int f, int *stack, int nbmax)
{
  int x,i,nb;
  if (n==-1) return 0;
  for(x=n,i=0;tree[x].f==f && i<nbmax;x=tree[x].x,i++);
  if (i==nbmax)
    exit(1);
  nb=i+1;
  for(x=n;i>0;stack[i]=tree[x].y,x=tree[x].x,i--);
  stack[0]=x;
  return nb;
}

#define STACKSZ 3

int main(void)
{
  int stack[STACKSZ];
  int i,nb;
  tree = (node *)calloc(STACKSZ,sizeof(node));
  tree[0].f = NODE;
  tree[0].x = 1;
  tree[0].y = 2;
  nb=listtostack(0,1,stack,STACKSZ);
  printf("nb=%d\n",nb);
  for(i=0;i<nb;i++)
    printf("%d: %d\n",i,stack[i]);
  return 0;
}



More information about the Gcc-bugs mailing list