Thread overview
compiler optimization bug
Nov 24, 2005
Tiago Gasiba
Nov 25, 2005
Tiago Gasiba
Nov 26, 2005
Thomas Kuehne
November 24, 2005
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.
November 25, 2005
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.
November 26, 2005
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