www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6665] New: DMD explodes!

reply d-bugmail puremagic.com writes:
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



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: -------
Sep 13 2011
next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Sep 14 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6665




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: -------
Sep 14 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6665




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: -------
Sep 14 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6665


David Simcha <dsimcha yahoo.com> changed:

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



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: -------
Oct 13 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6665




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: -------
Oct 13 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6665




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: -------
Oct 13 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6665


Maksim Zholudev <maximzms gmail.com> changed:

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



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: -------
Oct 19 2011
prev sibling parent d-bugmail puremagic.com writes:
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



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: -------
Oct 22 2011