Package: gcc-4.6
Version: 4.6.0-12
Severity: normal

Hello Debian GCC Maintainers,

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

Cheers,
-- 
Bill. <ballo...@debian.org>

Imagine a large red swirl here. 
#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;
}

Reply via email to