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]

Bug: erroneous code generated with i586-pc-linux-gnulibc1/egcs-2.91.05 980122 (w/--enable-haifa)


Hi,

  I've attached some small sample code which I believe compiles incorrectly
  when no optimizations are used.  In particular, the function C::f(A,int)
  contains the following assembly code snippet:

.LCFI37:
        movl 8(%ebp),%ebx
        movl 12(%ebp),%edx
        movl %edx,%eax
        movl 16(%ebp),%esi
        movl %eax,%edx
        movl $0,-4(%ebp)
.L25:
        movl -4(%ebp),%edx
        cmpl %edx,4(%ebx)
        ja .L28
        jmp .L26
        .align 4
.L28:
        movl -4(%ebp),%ecx
        movl %esi,%edx
        sarl %cl,%edx
        movl %edx,%ecx
        andl $1,%ecx
        pushl %ecx
.LCFI38:
        movl %eax,%eax
        pushl %eax
.LCFI39:
        movl -4(%ebp),%eax
        movl %eax,%edx
        leal 0(,%edx,4),%eax
        movl %eax,%edx
        addl (%ebx),%edx
        pushl %edx
.LCFI40:
        call f__1BG1Ai
        addl $12,%esp
.LCFI41:
.L27:
        incl -4(%ebp)
        jmp .L25

  The line labelled '.LCFI38' suspiciously does nothing.  The first time
  through the loop, the %eax register contains the proper value due to the code
  near '.LCFI37'.  The second time, however, the %eax register has been
  corrupted, and is not set properly before being pushed on the stack.

  I have not had a chance to install the latest snapshot in order to check
  for this, but I'm downloading it now.

  I've tried to make the program so that it returns -1 if the above bug occurs,
  otherwise, it returns 0.  To do this, I use a 'password' value of 3270.  If,
  for some reason, buggy code just happens to generate this value, the program
  will _appear_ to function correctly.  I doubt that this will occur often.

// compiling with 'g++ bug.cc' makes a.out return -1.
// compiling with 'g++ -O bug.cc' makes a.out return 0.
class A  // class A must be able to fit in a register to show bug
{
public:
  int data;
  A():data(-1) {}
  A(int idata):data(idata) {}
  bool operator==(const A& rhs) { return data==rhs.data; }
};

class B
{
public:
  A a;
  B(){}
  void f(A R,int V);
};

void B::f(A R,int V)
{
  if(R==3270) a=A(0);
}

class C
{
  B* Bs;
  unsigned width;

public:
  C(unsigned iwidth):Bs(new B[iwidth]),width(iwidth) {}

  void f(A R,int V)
  {
    for(unsigned i=0; i<width; i++) Bs[i].f(R,(V>>i)&1);
  }
  int operator[](int idx) { return Bs[idx].a.data; }
};

int main()
{
  A a(3270);
  C c(3);
  c.f(a,-4);
  return c[1];
}


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