www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - problem compiling with optimizations enabled

reply "darkstalker" <slayerbeast gmail.com> writes:
I have the following source:

---
import std.stdio;

string ascii = " .:;+=xX$&";

void main()
{
     for (idouble i = -2i; i <= 2i; i += .125i)
     {
         for (double r = -2; r <= 2; r += .0625)
         {
             auto c = r + i;
             auto z = 0 + 0i;
             int iter;
             do
             {
                 z = z * z + c;
                 if (z.re * z.re + z.im * z.im > 4)
                     break;
                 ++iter;
             } while (iter < ascii.length - 1);
             write(ascii[iter]);
         }
         writeln();
     }
}
---

It compiles and works normally, unless i turn in optimizations:

---
$ dmd -O program.d
Internal error: backend/gloop.c 3400
---

Is this a bug? or something wrong in my code?

compiler: DMD64 D Compiler v2.058 (64 bit)
OS: gentoo linux x86_64
Mar 31 2012
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
darkstalker:

 Is this a bug? or something wrong in my code?
Congratulations, it's another compiler bug. On Windows 32 bit this code behaves in another way, it doesn't crash: import std.stdio; void main() { for (idouble j = -2i; j <= 2i; j += 0.125i) { for (double r = -2; r <= 2; r += 0.0625) { cdouble c = r + j; writeln(c.re, " ", c.im); } } } Without -O: -2 -2 -1.9375 -2 -1.875 -2 -1.8125 -2 -1.75 -2 ... 1.75 2 1.8125 2 1.875 2 1.9375 2 2 2 With -O: -0 -9.88131e-324 -0 -9.88131e-324 -0 -9.88131e-324 -0 -9.88131e-324 -0 -9.88131e-324 -0 -9.88131e-324 -0 -9.88131e-324 ... Bye, bearophile
Mar 31 2012
prev sibling next sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 3/31/2012 4:35 PM, darkstalker wrote:
 ---
 $ dmd -O program.d
 Internal error: backend/gloop.c 3400
 ---

 Is this a bug? or something wrong in my code?
Any internal error messages are compiler bugs. Please add it to bugzilla: http://d.puremagic.com/issues/enter_bug.cgi?product=D
Mar 31 2012
prev sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
On Saturday, 31 March 2012 at 23:35:41 UTC, darkstalker wrote:

And I have already seen the image in that gravatar somewhere.

Bye,
bearophile
Mar 31 2012