www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - compiler optimization bug

reply Tiago Gasiba <tiago.gasiba gmail.com> writes:
The following code works fine without the -O option (with DMD 0.139 on Linux)
but goes crazy with -O:

import std.string;

/*
Different results

  compiling with "dmd bug.d"
    1+0i  0+1i  1+1i
    1+-1i  1+1i  2+0i

  compiling with "dmd -O bug.d"
    1+0i  0+1i  1+1i
    0+0i  0+0i  0+0i
*/

int main( ){
  static cdouble[] A = [1, 1i, 1+1i];
  int    ii;

  foreach( cdouble z; A )
    printf("%.*s  ",toString(z));
  printf("\n");

  for( ii=0; ii<A.length; ii++ )
    A[ii] += -1i*A[ii];

  foreach( cdouble z; A )
    printf("%.*s  ",toString(z));
  printf("\n");

  return 0;
}

Tiago

-- 
Tiago Gasiba (M.Sc.) - http://www.gasiba.de
Everything should be made as simple as possible, but not simpler.
Nov 24 2005
next sibling parent Tiago Gasiba <tiago.gasiba gmail.com> writes:
Tiago Gasiba schrieb:

 The following code works fine without the -O option (with DMD 0.139 on
 Linux) but goes crazy with -O:
 
 import std.string;
 
 /*
 Different results
 
   compiling with "dmd bug.d"
     1+0i  0+1i  1+1i
     1+-1i  1+1i  2+0i
 
   compiling with "dmd -O bug.d"
     1+0i  0+1i  1+1i
     0+0i  0+0i  0+0i
 */
 
 int main( ){
   static cdouble[] A = [1, 1i, 1+1i];
   int    ii;
 
   foreach( cdouble z; A )
     printf("%.*s  ",toString(z));
   printf("\n");
 
   for( ii=0; ii<A.length; ii++ )
     A[ii] += -1i*A[ii];
 
   foreach( cdouble z; A )
     printf("%.*s  ",toString(z));
   printf("\n");
 
   return 0;
 }
 
 Tiago
 
Same happens with DMD 0.140 on Linux. Tiago -- Tiago Gasiba (M.Sc.) - http://www.gasiba.de Everything should be made as simple as possible, but not simpler.
Nov 25 2005
prev sibling parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Tiago Gasiba schrieb am 2005-11-24:
 The following code works fine without the -O option (with DMD 0.139 on Linux)
but goes crazy with -O:

 import std.string;

 /*
 Different results

   compiling with "dmd bug.d"
     1+0i  0+1i  1+1i
     1+-1i  1+1i  2+0i

   compiling with "dmd -O bug.d"
     1+0i  0+1i  1+1i
     0+0i  0+0i  0+0i
 */

 int main( ){
   static cdouble[] A = [1, 1i, 1+1i];
   int    ii;

   foreach( cdouble z; A )
     printf("%.*s  ",toString(z));
   printf("\n");

   for( ii=0; ii<A.length; ii++ )
     A[ii] += -1i*A[ii];

   foreach( cdouble z; A )
     printf("%.*s  ",toString(z));
   printf("\n");

   return 0;
 }

 Tiago
Added to DStress as http://dstress.kuehne.cn/run/c/cfloat_06.d http://dstress.kuehne.cn/run/c/cdouble_06.d http://dstress.kuehne.cn/run/c/creal_30.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFDiTf03w+/yD4P9tIRAm7JAJsGSjyXmlFxcQNwY6dqLPG0QfCkMACbBN+6 bpf6qLOGfnj3Nmr1ZxFcyJE= =2v7E -----END PGP SIGNATURE-----
Nov 26 2005