Bug 10086 – ICE(glue.c) or wrong code on passing variable as template value parameter

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-05-15T09:31:00Z
Last change time
2013-08-27T13:21:01Z
Keywords
ice, industry, pull, wrong-code
Assigned to
nobody
Creator
luka8088

Attachments

IDFilenameSummaryContent-TypeSize
1214dlang-bug.zipcodeapplication/zip2617

Comments

Comment #0 by luka8088 — 2013-05-15T09:31:44Z
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]])
Comment #3 by admin — 2013-05-15T09:41:39Z
The order of how you compile the files matters: ─[dav1d@archbox][/tmp/b/dlang-bug]╼ dmd program.d lngex/m1.d alter/callback.d -unittest ─[dav1d@archbox][/tmp/b/dlang-bug]╼ ./program S1([[1]]) ─[dav1d@archbox][/tmp/b/dlang-bug]╼ dmd -unittest -ofprogram program.d lngex/m1.d alter/callback.d ─[dav1d@archbox][/tmp/b/dlang-bug]╼ dmd -unittest -ofprogram program.d lngex/m1.d alter/callback.d && ./program S1([[1]]) ─[dav1d@archbox][/tmp/b/dlang-bug]╼ rm program ─[dav1d@archbox][/tmp/b/dlang-bug]╼ dmd -unittest -ofprogram program.d lngex/m1.d alter/callback.d && ./program S1([[1]]) ─[dav1d@archbox][/tmp/b/dlang-bug]╼ dmd -unittest -ofprogram lngex/m1.d alter/callback.d program.d && ./program S1([[1]]) ─[dav1d@archbox][/tmp/b/dlang-bug]╼ dmd -unittest -ofprogram alter/callback.d lngex/m1.d program.d && ./program ./program(_D4core7runtime18runModuleUnitTestsUZb19unittestSegvHandlerUiPS4core3sys5posix6signal9siginfo_tPvZv+0x3e)[0x457cde] [1] 2047 segmentation fault (core dumped) ./program
Comment #4 by maxim — 2013-05-15T11:14:38Z
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.
Comment #7 by k.hara.pg — 2013-08-20T03:01:51Z
Comment #8 by github-bugzilla — 2013-08-27T13:20:21Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/78ca53ef95d71e436c8cdfe70a626e275be6b3c2 fix Issue 10086 - ICE(glue.c) or wrong code on passing variable as template value parameter https://github.com/D-Programming-Language/dmd/commit/274718428aee31c5e52d4ce66a932a2e0f4af1e3 Merge pull request #2485 from 9rnsr/fix10857 Issue 10086 & 10857 - Adjust instantiated template process order, and fix ICE in glue.c