D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4254 - ICE(mtype.c): function with const inout parameter
Summary: ICE(mtype.c): function with const inout parameter
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-invalid-code, patch
Depends on:
Blocks:
 
Reported: 2010-05-30 17:02 UTC by Ellery Newcomer
Modified: 2010-11-07 13:45 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Ellery Newcomer 2010-05-30 17:02:55 UTC
The code:

void bub(const inout int other) {}
void main() {
    bub(1);
}

The result:

dmd: mtype.c:1155: Type* Type::addMod(unsigned int): Assertion `0' failed.
/home/ellery/bin/dmd: line 3: 25241 Aborted                 (core dumped) /home/ellery/Downloads/dmd2046/linux/bin/dmd $*

dmd  2.046
Comment 1 Don 2010-11-01 18:50:04 UTC
In mtype.c, 
Type::addstorageclass() can result in any combination of const, shared, wild.
But not all possible combinations are considered in Type::addmod.
The missing cases are MODconst | MODwild and MODshared | MODconst | MODwild.
Apparently, if both const and wild are present, wild should be ignored.

So, Type::addStorageClass(), line 1180 should have 'else' added, to make MODconst and MODwild mutually exclusive:


    if (stc & STCimmutable)
        mod = MODimmutable;
    else
    {   if (stc & (STCconst | STCin))
            mod = MODconst;
-        if (stc & STCwild)
+        else if (stc & STCwild)
            mod = MODwild;
        if (stc & STCshared)
            mod |= MODshared;
    }
Comment 2 Walter Bright 2010-11-07 13:45:21 UTC
http://www.dsource.org/projects/dmd/changeset/740