Bug 8262 – ICE(mtype.c) alias this to alias of an expression tuple

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-06-18T12:30:13Z
Last change time
2017-12-18T22:58:16Z
Keywords
ice, pull
Assigned to
No Owner
Creator
timon.gehr
See also
http://d.puremagic.com/issues/show_bug.cgi?id=8735

Comments

Comment #0 by timon.gehr — 2012-06-18T12:30:13Z
template Seq(T...) { alias T Seq; } struct S{ int s; alias Seq!s _; alias _ this; } import std.stdio; void main(){ writeln(S.init); } Crashes DMD 2.059 with: dmd: mtype.c:1279: Type* Type::aliasthisOf(): Assertion `d->type' failed.
Comment #1 by maximzms — 2013-02-05T08:00:07Z
Crashes both DMD 2.061 and Git head with: -------------------- dmd: aliasthis.c:100: virtual void AliasThis::semantic(Scope*): Assertion `t' failed. --------------------
Comment #2 by hsteoh — 2014-07-17T18:56:27Z
Wow. This *still* doesn't work on git HEAD: dmd now segfaults.
Comment #3 by hsteoh — 2014-07-17T19:00:14Z
Stack trace: #0 0x0000000000410199 in TypeStruct::implicitConvTo(Type*) () #1 0x00000000004c8213 in IsExp::semantic(Scope*) () #2 0x00000000004de990 in AndAndExp::semantic(Scope*) () #3 0x00000000004de924 in AndAndExp::semantic(Scope*) () #4 0x00000000004de924 in AndAndExp::semantic(Scope*) () #5 0x00000000004de924 in AndAndExp::semantic(Scope*) () #6 0x00000000004b4769 in StaticIfCondition::include(Scope*, ScopeDsymbol*) () #7 0x000000000043d637 in ConditionalStatement::flatten(Scope*) () #8 0x00000000004437d1 in CompoundStatement::semantic(Scope*) () #9 0x00000000004ede13 in FuncDeclaration::semantic3(Scope*) () #10 0x00000000004504c4 in TemplateInstance::semantic3(Scope*) () #11 0x0000000000454d83 in TemplateInstance::trySemantic3(Scope*) () #12 0x000000000045c2e3 in TemplateInstance::semantic(Scope*, Array<Expression*>*) [clone .part.63] () #13 0x000000000045c87f in functionResolve(Match*, Dsymbol*, Loc, Scope*, Array<RootObject*>*, Type*, Array<Expression*>*) () #14 0x00000000004ec05e in resolveFuncCall(Loc, Scope*, Dsymbol*, Array<RootObject*>*, Type*, Array<Expression*>*, int) () #15 0x00000000004d3c33 in CallExp::semantic(Scope*) [clone .part.134] () #16 0x000000000043fd9b in ExpStatement::semantic(Scope*) () #17 0x0000000000443b6a in CompoundStatement::semantic(Scope*) () #18 0x00000000004ede13 in FuncDeclaration::semantic3(Scope*) () #19 0x0000000000407a50 in Module::semantic3() () #20 0x000000000040526c in tryMain(unsigned long, char const**) () #21 0x00007ffff7015b45 in __libc_start_main (main=0x402490 <main>, argc=2, argv=0x7fffffffeb68, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffeb58) at libc-start.c:287 #22 0x00000000004029c5 in _start ()
Comment #4 by hsteoh — 2014-07-17T19:14:40Z
Cause of segfault: aliasthisOf() returned NULL to implicitConvTo().
Comment #5 by hsteoh — 2014-07-17T20:03:30Z
And the reason is because aliasthisOf() does not expect a TypeTuple; it expects a variable declaration, a function, an enum, or a template. Normally, TypeTuples cannot appear in an alias this due to the current grammar, but there is a loophole where they can be masked by another layer of alias, as in the code given here, so it leads into this unhandled case.
Comment #6 by hsteoh — 2014-09-25T05:22:57Z
Comment #7 by r.sagitario — 2014-11-28T17:24:21Z
Here's another example of a crash at the same location reduced by dustmite: struct Tuple9709(T...) { alias T expand; alias expand this; } auto data = RTInfoImpl2!(Tuple9709!1); template RTInfoImpl2(T) { static if (is(T D == U)) immutable(RTInfoData) RTInfoImpl2 ; } [this is also triggered by some RTInfo compiled with the dmd test suite.] There are some code locations that check the pointer returned by aliasthisOf(), some do not. Should these be added in the places where the checks are missing?
Comment #8 by r.sagitario — 2014-12-06T17:45:14Z
https://github.com/D-Programming-Language/dmd/pull/4195 avoids the crash, but doesn't add implicite conversion for tuples.
Comment #9 by github-bugzilla — 2017-12-12T22:45:34Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/2f27c59732481880545ca65a4641806087cc23e7 fix issue 8262 - ICE(mtype.c) alias this to alias of an expression tuple check return of aliasthisOf https://github.com/dlang/dmd/commit/4616d4485102fc4650d14d185e224a621c25d965 Merge pull request #4195 from rainers/aliasthisof Issue 8262 - ICE(mtype.c) alias this to alias of an expression tuple merged-on-behalf-of: Andrei Alexandrescu <[email protected]>
Comment #10 by github-bugzilla — 2017-12-18T22:58:16Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/2f27c59732481880545ca65a4641806087cc23e7 fix issue 8262 - ICE(mtype.c) alias this to alias of an expression tuple https://github.com/dlang/dmd/commit/4616d4485102fc4650d14d185e224a621c25d965 Merge pull request #4195 from rainers/aliasthisof