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);
}
Comment #1 by clugdbug — 2011-09-14T05:16:24Z
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;
Comment #2 by iteronvexor — 2011-09-14T13:03:36Z
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);
}
Comment #3 by clugdbug — 2011-09-14T18:15:21Z
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.
Comment #4 by dsimcha — 2011-10-13T10:53:08Z
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
Comment #5 by dsimcha — 2011-10-13T11:37:07Z
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
Comment #6 by dsimcha — 2011-10-13T11:38:40Z
BTW, all this stuff works on the latest GDC, so it's definitely not in any code shared between DMD and GDC.
Comment #7 by maximzms — 2011-10-19T07:37:08Z
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)