public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/49419] New: [4.6/4.7 regression] gcc -O2 miscompiles gp2c
@ 2011-06-15 11:11 doko at ubuntu dot com
  2011-06-15 11:41 ` [Bug target/49419] " rguenth at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: doko at ubuntu dot com @ 2011-06-15 11:11 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2011-06-16 18:19 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-15 11:11 [Bug target/49419] New: [4.6/4.7 regression] gcc -O2 miscompiles gp2c doko at ubuntu dot com
2011-06-15 11:41 ` [Bug target/49419] " rguenth at gcc dot gnu.org
2011-06-15 11:55 ` mikpe at it dot uu.se
2011-06-15 11:56 ` jakub at gcc dot gnu.org
2011-06-15 12:19 ` jakub at gcc dot gnu.org
2011-06-15 12:30 ` jakub at gcc dot gnu.org
2011-06-15 15:00 ` jakub at gcc dot gnu.org
2011-06-15 16:04 ` [Bug tree-optimization/49419] " jakub at gcc dot gnu.org
2011-06-16  7:46 ` jakub at gcc dot gnu.org
2011-06-16  7:55 ` jakub at gcc dot gnu.org
2011-06-16  8:19 ` jakub at gcc dot gnu.org
2011-06-16 18:19 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).