Attached code compiles bug segfaults on both:
Windows_NT luka8088-PC 6.1 7601+Service_Pack_1
Linux atom 2.6.32-5-686 #1 SMP Mon Oct 3 04:15:24 UTC 2011 i686 GNU/Linux
I have no idea way :$
Comment #1 by luka8088 — 2013-05-15T09:32:28Z
Created attachment 1214
code
Comment #2 by luka8088 — 2013-05-15T09:33:11Z
Make sure it is compiled as -unittest, correct output should be: S1([[1]])
Reduced
------ m1.d -----
module m1;
import std.stdio;
import callback;
struct S1 {
int[][] a1 = [[1]];
}
@safe auto f1 (S1 r, bool o, dchar a, dchar b) {
return r;
}
@safe auto f2 (T1, T2) (S1 r, T1 g, T2 h) {
alias cpt = bind!(f1, r);
return f3!(cpt!(bool, dchar, dchar))(g, h);
}
@safe auto f3 (alias l = (a, b, c) => 0, T1, T2) (T1 d, T2 e) {
return l(true, 'a', 'b');
}
void main() {
S1 s1;
auto z = bind!(f2, s1)("", "");
writeln(z);
}
----callback.d ----
module callback;
template bind (alias f, bindValues...) {
auto bind (types...) (types values) {
return f(bindValues, values);
}
}
------------------
If compilation starts with 'callback' the program crashes, can confirm in 2.063 git head.
Comment #5 by maxim — 2013-05-15T12:08:18Z
Further reduced:
-----callback.d-----
module callback;
auto bind(alias f, bindValues...)()
{
auto bind(types...) (types values)
{
return f(bindValues, values);
}
return bind();
}
----m1.d--------
import callback;
extern(C) int printf(const char*, ...);
struct S1 {
int a1 = 1;
}
@safe auto f1 (S1 r) {
return r;
}
@safe auto f2()(S1 r) {
return bind!(f1, r);
}
void main() {
S1 s1;
auto z = bind!(f2, s1)();
printf("%d\n", z.a1);
}
-------------------------
Compile with callback as first argument, program prints garbage.
The problem appears in:
Dump of assembler code for function _D2m14mainFZv43__T4bindS62m12f2S23_D2m14mainFZv2s1S2m12S1Z4bindMFNfZS2m12S19__T4bindZ4bindMFNfZS2m12S1:
0x000000000041a1bc <+0>: push %rbp
0x000000000041a1bd <+1>: mov %rsp,%rbp
0x000000000041a1c0 <+4>: sub $0x10,%rsp
=> 0x000000000041a1c4 <+8>: mov (%rdi),%edi
0x000000000041a1c6 <+10>: callq 0x41a1d4 <_D2m17__T2f2Z2f2FNfS2m12S1ZS2m12S1>
0x000000000041a1cb <+15>: mov %rbp,%rsp
0x000000000041a1ce <+18>: pop %rbp
0x000000000041a1cf <+19>: retq
End of assembler dump.
If m1.d is compiled first, instruction is mov -0x8 (%rdi),%edi which is correct (function got RBP as argument, so it should read 8 bytes below).
Moreover, there is ice here: if you transform f2() from function template to template (again, you need to compile callback first), you get:
m1.d(13): Error: function m1.f2 compiler error, parameter 'r', bugzilla 2962?
dmd: glue.c:817: virtual void FuncDeclaration::toObjFile(int): Assertion `0' failed.
Aborted
Comment #6 by maxim — 2013-05-15T12:19:29Z
After reading issue 2962 I raise status to critical because this bug seems to raise old nasty bug marked as fixed and critical.