Thread overview
[Issue 4869] New: auto return + inheritance + modules = compiler crashes
Sep 15, 2010
David Simcha
Sep 15, 2010
Don
[Issue 4869] auto return + inheritance + modules = compiler crashes(toctype.c)
Sep 15, 2010
Don
Sep 15, 2010
Don
Sep 15, 2010
Don
Sep 22, 2010
Walter Bright
September 15, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4869

           Summary: auto return + inheritance + modules = compiler crashes
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: dsimcha@yahoo.com


--- Comment #0 from David Simcha <dsimcha@yahoo.com> 2010-09-14 19:13:28 PDT ---
The following code crashes both DMD 2.048 and 2.049 beta on Windows:

// Module a.d
class Base {
    auto fun() { return 1; }
}

// Module b.d
import a;

class Derived : Base {}

// Command
dmd -c b.d


Any of the following will prevent this bug from being reproduced:

1.  Changing the return type of fun from auto to int.
2.  Passing both modules to DMD at once.
3.  Putting both classes in the same module.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 15, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4869


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2010-09-14 20:52:39 PDT ---
Not a regression. This fails on 2.026 and later.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 15, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4869


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|auto return + inheritance + |auto return + inheritance +
                   |modules = compiler crashes  |modules = compiler
                   |                            |crashes(toctype.c)


--- Comment #2 from Don <clugdbug@yahoo.com.au> 2010-09-14 21:02:06 PDT ---
The segfault should be turned into an ICE with this code: toctype.c, line 254
TypeFunction::toCtype()

        if (varargs != 1)
            t->Tflags |= TFfixed;
        ctype = t;
+        assert(next);
        t->Tnext = next->toCtype();

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 15, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4869



--- Comment #3 from Don <clugdbug@yahoo.com.au> 2010-09-14 23:57:45 PDT ---
This is happening because semantic3() isn't run on the base class function. Bug 3602 has a similar root cause.

A workaround is to use the function in module b.d. This forces semantic3 to be
run on 'fun'.
void workaround(Derived d)
{
   auto k = d.fun();
}


Mitigation patch (turns it into rejects-valid):
---------
tocsym.c, line 349, FuncDeclaration::toSymbol()

        s = symbol_calloc(id);
        slist_add(s);
+        // Ensure function has a return value
+        if (type->ty == Tfunction && !((TypeFunction *)type)->next)
+        {
+            error("Internal Compiler Error. See Bugzilla 4869.");
+            // Prevent a later crash
+            ((TypeFunction *)type)->next = Type::tint32;
+        }
        {
            s->prettyIdent = toPrettyChars();
            s->Sclass = SCglobal;
            symbol_func(s);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 15, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4869


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #4 from Don <clugdbug@yahoo.com.au> 2010-09-15 05:06:45 PDT ---
Proper patch. The assert in comment 2 should still be added.


toobj.c line 790. ClassDeclaration::toObjFile(). Ensure each function has had semantic3 run on it, if the return type is still unknown. (Ideally, this should happen earlier on, but better late than never).

    for (; i < vtbl.dim; i++)
    {
        FuncDeclaration *fd = ((Dsymbol *)vtbl.data[i])->isFuncDeclaration();

        //printf("\tvtbl[%d] = %p\n", i, fd);
        if (fd && (fd->fbody || !isAbstract()))
        {
+            // Ensure function has a return value (Bugzilla 4869)
+            if (fd->type->ty == Tfunction && !((TypeFunction
*)fd->type)->next)
+            {
+                assert(fd->scope);
+                fd->semantic3(fd->scope);
+            }
            Symbol *s = fd->toSymbol();

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 22, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4869


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> 2010-09-22 16:18:38 PDT ---
http://www.dsource.org/projects/dmd/changeset/684

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------