This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

incorrect sparc code emitted by gcc 2.8.1


This program exhibits a bug in gcc 2.8.1 on Sparc 20 Solaris 2.6.

Basically, 
	  sp->i = ii;
acts like
          sp.i = ii;

This program does not exhibit the bug in GCC: (GNU) 2.95.1 19990816
(release), but that doesn't mean that the bug was fixed.  It might
just be that the new register allocation scheme hid the bug.  It
took some doing to set up a small example, and gcc 2.95.1 did
things differently and produced code somewhat like gcc 2.8.1
did before I added enough variables and loops to force things
out of registers.

carbon% uname -a
SunOS carbon 5.6 Generic_105181-15 sun4u sparc SUNW,Ultra-2

Some lines from /usr/local/src/gcc-2.8.1/config.status
host='sparc-sun-solaris2.6'
build='sparc-sun-solaris2.6'
target='sparc-sun-solaris2.6'
target_alias='sparc-sun-solaris2.6'
srcdir='.'
subdirs=' ada cp objc'
oldstyle_subdirs=' ada objc'
symbolic_link='ln -s'
version_dep=''
program_transform_set=''
program_transform_name='s,x,x,'
dep_host_xmake_file=' ./config/sparc/x-sysv4'
host_xmake_file='sparc/x-sysv4'
dep_tmake_file=' ./config/sparc/t-sol2'
tmake_file='sparc/t-sol2'
thread_file='single'
version='2.8.1'
local_prefix='/usr/local'
build_install_headers_dir='install-headers-tar'
build_exeext=''
out_file='sparc/sparc.c'
gdb_needs_out_file_path=''
SET_MAKE=''
build_broken_install='yes'
target_list='all.build all.cross start.encap rest.encap 	info dvi 	install-normal install-common install-info install-man 	uninstall distdir 	mostlyclean clean distclean extraclean maintainer-clean 	stage1 stage2 stage3 stage4'
target_overrides='Make-target'
host_overrides='Make-host'
cross_defines=''
cross_overrides='/dev/null'
build_overrides='/dev/null'


-------------- cut here ----------------
/* bug.c

This program exhibits a bug in gcc 2.8.1.
Basically, 
	  sp->i = ii;
acts like
          sp.i = ii;

This program does not exhibit the bug in GCC: (GNU) 2.95.1 19990816
(release), but that doesn't mean that the bug was fixed.  It might
just be that the new register allocation scheme hid the bug.

% gcc -O1 -ffast-math -msupersparc bug.c -g -o bug
% gcc --version
2.8.1
% bug
bug.c:22: failed assertion `sp != 0'
Abort (core dumped)
% gcc -S -g -O1 -ffast-math -msupersparc bug.c

Part of bug.s, with annotations:

.stabn 68,0,227,.LM102-main
.LM102:
	ld [%i1+12],%o0
	sethi %hi(-80108),%g3
	or %g3,%lo(-80108),%g3
	add %g3,%fp,%g3

;;; This is how it should be done.  
	ld [%g3],%g2
	st %o0,[%g2+12]
.stabn 68,0,228,.LM103-main
.LM103:
	sethi %hi(-80100),%g2
	or %g2,%lo(-80100),%g2
	add %g2,%fp,%g2
	ld [%g2],%g3
	sethi %hi(-80108),%g2
	or %g2,%lo(-80108),%g2
	add %g2,%fp,%g2

;;; This is how it should be done.  
	ld [%g2],%g2
	st %g3,[%g2+4]
.stabn 68,0,229,.LM104-main
.LM104:
	sethi %hi(-80096),%g3
	or %g3,%lo(-80096),%g3
	add %g3,%fp,%g3
	ld [%g3],%g3
	sethi %hi(-80108),%g2
	or %g2,%lo(-80108),%g2
	add %g2,%fp,%g2

;;; Missing the ld [%g2],%g2
	st %g3,[%g2]
.stabn 68,0,230,.LM105-main
.LM105:
	sethi %hi(-80104),%g3
	or %g3,%lo(-80104),%g3
	add %g3,%fp,%g3
	ld [%g3],%g3
	sethi %hi(-80108),%g2
	or %g2,%lo(-80108),%g2
	add %g2,%fp,%g2

;;; Missing the ld [%g2],%g2
	st %g3,[%g2+8]
.stabn 68,0,232,.LM106-main
.LM106:
	sethi %hi(-80108),%g2
	or %g2,%lo(-80108),%g2
	add %g2,%fp,%g2
	call func,0
	ld [%g2],%o0




*/

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

struct s {
  int i;
  int j;
  int k;
  int l;
};

int * func (struct s *);
int * func2 (int *,int *,int *,int *,int *,int *,int *,int *);
struct s *spfunc(void);


int * func (struct s *sp)
{
  int *p = (int *) malloc (sizeof(int) /* * sp->i*/);

  assert (sp != 0);
  p[0] = 1;
  return p;
}
int * func2 (int *a,int *b,int *c,int *d,int *e,int *f,int *g,int *h)
{
  return (int *) malloc (sizeof(int) /* * (a[0] + b[0] + c[0] + d[0] + e[0] + f[0] + g[0] + h[0])*/ );
}

struct s *spfunc(void)
{
  return (struct s *) malloc (sizeof(struct s));
}

int zero (void)
{
  return 0;
}

int
main (int argc, char *argv[])
{
  int big_array[10000];
  register int i, j, k, l;
  register int *i1, *i2, *i3, *i4, *i5, *i6, *i7, *i8;
  register int *j1, *j2, *j3, *j4, *j5, *j6, *j7, *j8;
  int ii, jj, kk;
  struct s *sp = spfunc();
  struct s *sp1 = spfunc();
  struct s *sp2 = spfunc();
  struct s *sp3 = spfunc();
  struct s *sp4 = spfunc();
  struct s *sp5 = spfunc();
  struct s *sp6 = spfunc();
  struct s *sp7 = spfunc();
  struct s *sp8 = spfunc();
  struct s *sp9 = spfunc();
  struct s *spa = spfunc();
  struct s *spb = spfunc();
  struct s *spc = spfunc();
  int *k1, *k2, *k3, *k4, *k5, *k6, *k7, *k8;
  int *l1, *l2, *l3, *l4, *l5, *l6, *l7, *l8;
  int big_array2[10000];

  /*
  sp->i = 0;
  sp2->i = 0;
  sp3->i = 0;
  */

  for (i = 0; i < 10; i++) {
    for (j = 0; j < 10; j++) {
      for (k = 0; k < 10; k++) {
	for (l = 0; k < 10; k++) {
	  ii = zero();
	  jj = zero();
	  kk = zero();
	  i1 = func(sp3)+i;
	  i2 = func(sp3)+j;
	  i3 = func(sp3)+k;
	  i4 = func(sp3)+l;
	  i5 = func(sp3)+i;
	  i6 = func(sp3)+j;
	  i7 = func(sp3)+k;
	  i8 = func(sp3)+l;
	  j1 = func(sp3)+i;
	  j2 = func(sp3)+j;
	  j3 = func(sp3)+k;
	  j4 = func(sp3)+l;
	  j5 = func(sp3)+i;
	  j6 = func(sp3)+j;
	  j7 = func(sp3)+k;
	  j8 = func(sp3)+l;
	  k1 = func(sp3)+i;
	  k2 = func(sp3)+j;
	  k3 = func(sp3)+k;
	  k4 = func(sp3)+l;
	  k5 = func(sp3)+i;
	  k6 = func(sp3)+j;
	  k7 = func(sp3)+k;
	  k8 = func(sp3)+l;
	  l1 = func(sp3)+i;
	  l2 = func(sp3)+j;
	  l3 = func(sp3)+k;
	  l4 = func(sp3)+l;
	  l5 = func(sp3)+i;
	  l6 = func(sp3)+j;
	  l7 = func(sp3)+k;
	  l8 = func(sp3)+l;

	  sp1->l = sp2->l;
	  sp1->j = *j1;
	  sp1->i = *k1;
	  sp1->k = *i1;
	  sp2->l = sp2->l;
	  sp2->j = *j2;
	  sp2->i = *k2;
	  sp2->k = *i2;
	  sp3->l = sp2->l;
	  sp3->j = *j3;
	  sp3->i = *k3;
	  sp3->k = *i3;
	  sp4->l = sp2->l;
	  sp4->j = *j4;
	  sp4->i = *k4;
	  sp4->k = *i4;
	  sp5->l = sp2->l;
	  sp5->j = *j5;
	  sp5->i = *k5;
	  sp5->k = *i5;
	  sp6->l = sp2->l;
	  sp6->j = *j6;
	  sp6->i = *k6;
	  sp6->k = *i6;
	  sp7->l = sp2->l;
	  sp7->j = *j7;
	  sp7->i = *k7;
	  sp7->k = *i7;
	  sp8->l = sp2->l; sp8->j = *j8; sp8->i = *k8; sp8->k = *i8;
	  sp9->l = sp2->l; sp9->j = *j8; sp9->i = *k8; sp9->k = *i8;
	  spa->l = sp2->l; spa->j = *j8; spa->i = *k8; spa->k = *i8;
	  spb->l = sp2->l; spb->j = *j8; spb->i = *k8; spb->k = *i8;
	  spc->l = sp2->l; spc->j = *j8; spc->i = *k8; spc->k = *i8;

	  sp->l = sp2->l;
	  sp->j = jj;
	  sp->i = ii;
	  sp->k = kk;

	  func(sp);
	  func2(i1,i2,i3,i4,i5,i6,i7,i8);
	  func2(j1,j2,j3,j4,j5,j6,j7,j8);
	  func2(k1,k2,k3,k4,k5,k6,k7,k8);
	  func2(l1,l2,l3,l4,l5,l6,l7,l8);
	}
      }
    }
  }
}

-------------- cut here ----------------

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]