Bug 14147 – Compiler crash on identical functions in a single module

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-02-08T09:44:27Z
Last change time
2020-03-21T03:56:40Z
Keywords
ice, pull
Assigned to
No Owner
Creator
Denis Gladkiy
Depends on
2789, 15217
See also
https://issues.dlang.org/show_bug.cgi?id=15217

Attachments

IDFilenameSummaryContent-TypeSize
1475main.dThe to crash DMD.text/plain507

Comments

Comment #0 by denis.gladkiy — 2015-02-08T09:44:27Z
Created attachment 1475 The to crash DMD. The compiler (2.066.1) crashes when compiling this: pure auto mul(const int[] left, const int[] right) { return zip(left, right).map!(a => a[0] * a[1]) ; } pure auto mul(const int[] left, const int[] right) { return zip(left, right).map!(a => a[0] * a[1]) ; } Assertion failure: 'type->ty != Tstruct || ((TypeStruct *)type)->sym == this' on line 912 in file 'struct.c' I've attached the code to reproduce the bug.
Comment #1 by ketmar — 2015-02-08T10:28:38Z
seems that this assert() is right, and the code in `StructDeclaration::semantic()` is missing one check. here we have a check for the same condition: if (type->ty == Tstruct && ((TypeStruct *)type)->sym != this) { TemplateInstance *ti = ((TypeStruct *)type)->sym->isInstantiated(); if (ti && isError(ti)) ((TypeStruct *)type)->sym = this; } seems that second `if` is missing `else` part with `error()`.
Comment #2 by k.hara.pg — 2015-02-08T13:34:35Z
Reduced test case: struct S(alias func) { void foo() { func(1); } } void main() { } pure auto mul(const int[] left, const int[] right) { S!(a => a)().foo(); } pure auto mul(const int[] left, const int[] right) { S!(a => a)().foo(); } In the two identical functions, the S!(a => a) will create different instances, but their mangled names are wrongly identical. Then It makes the internal compiler error (assertion failure).
Comment #3 by k.hara.pg — 2015-02-08T14:44:01Z
Comment #4 by github-bugzilla — 2018-01-24T11:39:20Z
Commit pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/ab47b8b0cf18d14c1ffbc97df6c8fb299971170a Issue 14147 - Compiler crash on identical functions in a single module (#7577) * fix Issue 2789 - Functions overloads are not checked for conflicts * Allow an overload declaration hack, which is actually used in druntime If two extern (C) functions are just declared with different signatures, they don't conflict. extern(C): alias sigfn_t = void function(int); alias sigfn_t2 = void function(int) nothrow @nogc; sigfn_t bsd_signal(int sig, sigfn_t func); sigfn_t2 bsd_signal(int sig, sigfn_t2 func) nothrow @nogc; // no error This behavior must be reconsidered in the future. * fix Issue 14147 - Compiler crash on identical functions in a single module * Allow an overload declaration hack, which is actually used in druntime * Fix the testsuite * PR 4396 Fixup * Remove duplicate definition in the DMD backend
Comment #5 by greensunny12 — 2018-03-01T05:09:17Z
This is still active due to regressions reported. See also https://github.com/dlang/dmd/pull/7969, https://github.com/dlang/dmd/pull/7577
Comment #6 by b2.temp — 2019-03-01T07:58:15Z
Can this be closed now ?
Comment #7 by greensunny12 — 2019-03-01T09:00:30Z
No, the PRs were reverted and the deprecation cycle is supposed to be started by https://github.com/dlang/dmd/pull/8429 which hasn't been merged yet.
Comment #8 by b2.temp — 2019-07-05T13:44:45Z
no crash anymore