Thread overview
[Issue 6665] New: DMD explodes!
[Issue 6665] Regression(2.055) ICE(cg87.c): static double inside closure
Sep 14, 2011
Don
Sep 15, 2011
Don
Oct 13, 2011
David Simcha
Oct 13, 2011
David Simcha
Oct 13, 2011
David Simcha
Oct 19, 2011
Maksim Zholudev
Oct 22, 2011
Walter Bright
September 13, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6665

           Summary: DMD explodes!
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: iteronvexor@gmail.com


--- Comment #0 from iteronvexor@gmail.com 2011-09-13 15:30:11 PDT ---
On a 64-bit Linux machine, with DMD 2.055

This gives:  '/Internal error: ../ztc/cg87.c 202'
void main(){

  auto f = (double m){ static double sum = 0.0; return sum += m * m; };
  double[] a = array(map!f(iota(1.0, 25.0, 1.0)));
  writeln(a);
}


This one compiles but I get Segmentation fault.
void main(){

   auto f = (double m){ /* static double sum = 0.0;*/ return m * m; };
   double[] a = array(map!f(iota(1.0, 25.0, 1.0)));
   writeln(a);
 }


This one compiles and runs.
 void main(){

   auto f = (double m){ /* static double sum = 0.0;*/ return m * m; };
   double[] a = array(map!f(array(iota(1.0, 25.0, 1.0))));
   writeln(a);
 }


Putting everything together, I still get 'Internal error: ../ztc/cg87.c 202'
with this one.
void main(){

  auto f = (double m){ static double sum = 0.0; return sum += m * m; };
  double[] a = array(map!f(array(iota(1.0, 25.0, 1.0))));
  writeln(a);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 14, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6665


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-valid-code
                 CC|                            |clugdbug@yahoo.com.au
            Summary|Internal error:             |Regression(2.055)
                   |../ztc/cg87.c 202           |ICE(cg87.c): static double
                   |                            |inside closure


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2011-09-14 05:16:24 PDT ---
Probably a result of the fix for bug 6505.
It may be 64 bit specific, I cannot reproduce on Windows. I'm assuming that the
imports are:

import std.algorithm;
import std.array;
import std.stdio;
import std.range;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 14, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6665



--- Comment #2 from iteronvexor@gmail.com 2011-09-14 13:03:36 PDT ---
Yes, the imports are what you have listed.

This might be just a Linux issue.  Here are the results for 32-bit Linux:

Compiles but gives 'Segmentation fault'
void main(){

  auto f = (double m){ static double sum = 0.0; return sum += m * m; };
  double[] a = array(map!f(iota(1.0, 25.0, 1.0)));
  writeln(a);
}


Compiles but gives 'Segmentation fault'
void main(){

  auto f = (double m){ /* static double sum = 0.0;*/ return m * m; };
  double[] a = array(map!f(iota(1.0, 25.0, 1.0)));
  writeln(a);
}


Compiles and runs
void main(){

  auto f = (double m){ /* static double sum = 0.0;*/ return m * m; };
  double[] a = array(map!f(array(iota(1.0, 25.0, 1.0))));
  writeln(a);
}


Compiles and runs
void main(){

  auto f = (double m){ static double sum = 0.0; return sum += m * m; };
  double[] a = array(map!f(array(iota(1.0, 25.0, 1.0))));
  writeln(a);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 15, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6665



--- Comment #3 from Don <clugdbug@yahoo.com.au> 2011-09-14 18:15:21 PDT ---
Compiling the first case with -inline gives an error:
c:\dmd\windows\bin\..\..\src\phobos\std\algorithm.d(423): Error: function D
main
 is a nested function and cannot be accessed from array

which is completely wrong -- why does it think main() is a nested function??? So even on Windows this shows a serious problem with the inliner. But the inlining bug isn't a regression, the same error message applies also as far back as 2.035.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 13, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6665


David Simcha <dsimcha@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dsimcha@yahoo.com


--- Comment #4 from David Simcha <dsimcha@yahoo.com> 2011-10-13 10:53:08 PDT ---
FWIW, I've found another way to reproduce this bug:

import std.range, std.algorithm;

double fun(double x) { return x; }

void main() {
    map!(fun)(indexed([1.0, 2], [0, 1]));
}

Using DMD64 on Linux (This is a 64-bit specific issue, adding -m32 makes it go away.  It also only happens with -release.)

dmd test.d -release
Internal error: ../ztc/cg87.c 202

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 13, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6665



--- Comment #5 from David Simcha <dsimcha@yahoo.com> 2011-10-13 11:37:07 PDT ---
Even more thoroughly reduced test case:

void main()
{
    auto foo = Indexed([1.0f, 2, 3], [1, 2, 3]);
}

@property ref T front(T)(T[] a)
{
    return a[0];
}

struct Indexed
{
    float[] _source;
    int[] _indices;

    @property float front(float newVal)
    {
        return _source[_indices.front] = newVal;
    }

}

$ dmd test.d -release
Internal error: ../ztc/cg87.c 202

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 13, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6665



--- Comment #6 from David Simcha <dsimcha@yahoo.com> 2011-10-13 11:38:40 PDT ---
BTW, all this stuff works on the latest GDC, so it's definitely not in any code shared between DMD and GDC.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 19, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6665


Maksim Zholudev <maximzms@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maximzms@gmail.com


--- Comment #7 from Maksim Zholudev <maximzms@gmail.com> 2011-10-19 07:37:08 PDT ---
More investigation.

----- test.d -----
struct Foo
{
    double[2][2] dat;

    double foo(size_t i, size_t j)
    {
        return dat[i][j] = 0;
    }
}

void main()
{
    Foo a;
}
------------------

Tested on Linux 64bit with dmd 2.055:
dmd -m32 test.d          -> OK
dmd -m64 test.d          -> Internal error: ../ztc/cg87.c 202
dmd -m32 -release test.d -> OK
dmd -m64 -release test.d -> OK

There is no error in any of the following cases:
  * "dat" is one-dimensional
  * one of the indexes in Foo.foo is constant (e.g. dat[i][0] = 0)
  * "int" or "real" used instead of "double" ("float" still produces the error)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 22, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6665


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #8 from Walter Bright <bugzilla@digitalmars.com> 2011-10-22 00:28:07 PDT ---
https://github.com/D-Programming-Language/dmd/commit/517098887b5dee1e91c69610b8c4056c17e191ce

https://github.com/D-Programming-Language/dmd/commit/6277161a9c606c6cdba37500a230e7d71a31d629

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------