does egcs get its sums right?

Stefan Schwarzer sts@ica1.uni-stuttgart.de
Wed Jan 13 13:44:00 GMT 1999


// Hi, 
//
// I have been following the egcs history for a while and this compiler bug
// has followed me from gcc-2.8.1 until now. 
// I can still reproduce it with egcs-1.1.1 on Ultra, Solaris 2.5.1 and 
// Solaris 7, but _not_ on Alpha DUNIX 4.0C. It only occurs in the
//  -O2 and -O3 optimization levels. 
//
// I dont include the .ii stuff, because apart from line number info it is 
// identical to the soiurce attached below. 
// I'd really appreciate if this bug would make it into your testsuite
//
// ok, here it comes:
// gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)
// SunOS boa.ica1.uni-stuttgart.de 5.7 Generic sun4u sparc SUNW,Ultra-1
//
// this is the wrong result:
// 20:57 boa_sts:~/bugs/gnu> g++ -O3 -Wall ini-egcs.cc
// 20:57 boa_sts:~/bugs/gnu> a.out
// 20:58 boa_sts:~/bugs/gnu> echo $status
// 5
// this is the expected result:
// 20:58 boa_sts:~/bugs/gnu> g++ -Wall ini-egcs.cc
// 20:58 boa_sts:~/bugs/gnu> a.out
// 20:58 boa_sts:~/bugs/gnu> echo $status
// 7
//
// Thanks for your nice work on egcs in any case!
//
// Stefan Schwarzer                office:  +49-(0)711-685-7606   fax: x-3658 
// Uni Stuttgart, ICA 1            e-mail:          sts@ica1.uni-stuttgart.de
// Pfaffenwaldring 27              pgp public key available on request/finger 
// 70569 Stuttgart, Germany             http://www.ica1.uni-stuttgart.de/~sts


struct XTVec{
  XTVec(){x[0]=x[1] =x[2] =0;}
  XTVec(double ax,double y=0.,double z=0.){x[0]=ax;x[1]=y; x[2]=z; }
  double& operator[](int);

  double x[3];
};

inline 
double & XTVec::operator[](int i){
  return x[i];
}

inline 
XTVec& operator+=(XTVec& lhs, XTVec& rhs){
  lhs[0]+=rhs[0];
  lhs[1]+=rhs[1];
  lhs[2]+=rhs[2];
  return lhs;
}

inline 
XTVec operator+(XTVec& lhs, XTVec& rhs){
  XTVec result(lhs);
  return result += rhs;
}

int main()
{
  XTVec ur(4.,0.,1.);
  XTVec ll(0.,2.,0.);
  XTVec initsum(ur + ll);

  // avoid i/o, sorry for the cast
  return (int) (initsum[0] + initsum[1] + initsum[2]);
}



More information about the Gcc-bugs mailing list