Bug 4434 – ICE(mtype.c, 887) alias with const, shared, or immutable
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2010-07-06T15:35:00Z
Last change time
2010-12-01T16:33:51Z
Keywords
ice-on-valid-code, patch
Assigned to
nobody
Creator
sean
Comments
Comment #0 by sean — 2010-07-06T15:35:16Z
Compile the following:
private struct MyStruct {}
alias shared MyStruct* MyShared;
If the parens are added to the second line, the assertion failure goes away.
Comment #1 by clugdbug — 2010-08-10T13:10:44Z
This one seems to be really general. I think it's the cause of very many compiler bugs. Here's a pile of cases which ICE.
struct MyStruct {}
alias const (MyStruct)* MyGoodConst; //OK
alias const MyStruct* MyConst; //ice
alias shared MyStruct* MyShared; //ice
alias shared MyStruct[] MySharedArray; //ice
alias int MyInt;
alias const MyInt[3] MyConstInt; // ice
It happens with const, shared, or immutable, and with *, [], [3], etc -- anything which is a BasicType2.
Interestingly it doesn't seem to happen with typedef, even though the code in parse.c is almost identical.
Comment #2 by clugdbug — 2010-08-11T00:51:57Z
This has to be a bug either in the parser, or in the type transitivity check.
I've added this line to check that the type being passed to the AliasDeclaration is correctly constructed. This test fails for the cases which work!!
---------
parse.c, 2335. Parser::parseBasicType()
case TOKconst:
// const(type)
nextToken();
check(TOKlparen);
t = parseType();
check(TOKrparen);
if (t->isShared())
t = t->makeSharedConst();
else
t = t->makeConst();
+ t->check();
break;
---------
// This test case compiles OK, but it fails the check above.
alias int MyInt;
typedef const (MyInt*) MyConstInt;
It's checking that const(MyInt*) is the same as const(const(MyInt)*) -- but it's isn't!
So really, the difference between the cases that work, and those which fail, is simply that the latter are checked. The only cases that pass everything are ones like: alias const int* XXX;
So either, makeConst() is wrong, or else AliasDeclaration is calling check() too early; or the check is wrong. I really don't know which it is.
Comment #3 by yao.gomez — 2010-09-15T21:40:02Z
I have the latest DMD2 compiler, and this also triggers this assertion:
---
static immutable u64 foo[1] = [0x123456789];
---
Note that the u64 identifier is not defined anywere. If I change it to ulong, it works (obviously). Maybe it has something to do with ids not defined or something.
The error messages that I get are:
> test.d(18): Error: identifier 'u64' is not defined
> test.d(18): Error: identifier 'u64' is not defined
> test.d(18): Error: u64 is used as a type
> Assertion failure: 'tn->mod == MODimmutable' on line 879 in file 'mtype.c'
Comment #4 by clugdbug — 2010-11-03T05:21:34Z
According to TDPL, const T[] is supposed to mean const(const(T)[]).
But currently, it isn't; it's const(mutable(T)[])
This happens because mtype.c, TypeNext::makeConst() includes a line which should be deleted:
if (ty != Tfunction && ty != Tdelegate &&
- (next->deco || next->ty == Tfunction) &&
!next->isImmutable() && !next->isConst())
{ if (next->isShared())
t->next = next->sharedConstOf();
else
t->next = next->constOf();
}
which means that it's not making the array contents const.
Same change also needs to be applied to TypeNext::makeShared(), makeSharedConst(), makeInvariant()
and possibly also to makeWild().
Test cases:
-----
struct Bug4434 {}
alias const Bug4434* IceConst4434;
alias shared Bug4434* IceShared4434;
alias shared Bug4434[] IceSharedArray4434;
alias immutable Bug4434* IceImmutable4434;
alias shared const Bug4434* IceSharedConst4434;
alias int MyInt4434;
alias const MyInt4434[3] IceConstInt4434;
alias immutable string[] Bug4830;
---
This patch also fixes these bugs:
Bug 4366 ICE(mtype.c) constrained template pure function with array/pointer parameter
Bug 4709 ICE(mtype.c): undefined variable in const struct
Bug 4743 ICE(mtype.c) involving "in UnknownType*"
Bug 4830 Regression(2.038) ICE mtype.c:879: void Type::check(): Assertion `tn->mod == 4' failed
Bug 4871 ICE(mtype.c 875) const alias
Bug 4964 ICE(mtype.c) casting to undefined types
Bug 4980 ICE(mtype.c) on unknown type in a shared class/struct
Comment #5 by bearophile_hugs — 2010-11-03T05:48:34Z