6665 – Regression(2.055) ICE(cg87.c): static double inside closure

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6665 - Regression(2.055) ICE(cg87.c): static double inside closure
Summary: Regression(2.055) ICE(cg87.c): static double inside closure
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P2 regression
Assignee: No Owner
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
Reported: 2011年09月13日 15:30 UTC by Caligo
Modified: 2011年10月22日 00:28 UTC (History)
4 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Caligo 2011年09月13日 15:30:11 UTC
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 Don 2011年09月14日 05:16:24 UTC
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 Caligo 2011年09月14日 13:03:36 UTC
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 Don 2011年09月14日 18:15:21 UTC
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 David Simcha 2011年10月13日 10:53:08 UTC
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 David Simcha 2011年10月13日 11:37:07 UTC
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 David Simcha 2011年10月13日 11:38:40 UTC
BTW, all this stuff works on the latest GDC, so it's definitely not in any code shared between DMD and GDC.
Comment 7 Maksim Zholudev 2011年10月19日 07:37:08 UTC
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)


AltStyle によって変換されたページ (->オリジナル) /