www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3500] New: Program behaves differently with -inline

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3500

           Summary: Program behaves differently with -inline
           Product: D
           Version: 2.035
          Platform: Other
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: nfxjfg gmail.com


--- Comment #0 from nfxjfg gmail.com 2009-11-12 10:20:47 PST ---
The following program behaves differently whether you pass -inline to dmd or
not.
The correct output is "A::x()", but with -inline, it outputs "B::x()".
Conclusion: the dmd inliner must be buggy.
I confirmed this with:
- dmd 1.051/Tango
- dmd 2.035/Phobos

Command line, failing binary: dmd bug.d -inline
Correct binary: dmd bug.d

Test using Tango:

import tango.util.log.Trace;

class A {
    void x() {
        Trace.formatln("A::x()");
    }
}

class B : A {
    override void x() {
        Trace.formatln("B::x()");
    }

    private void do_x() {
        super.x();
    }
}

void main() {
    B b = new B();
    b.do_x();
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 12 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3500



--- Comment #1 from nfxjfg gmail.com 2009-11-12 10:29:58 PST ---
D2 testcase.

import std.stdio;

class A {
    void x() {
        writefln("A::x()");
    }
}

class B : A {
    override void x() {
        writefln("B::x()");
    }

    private void do_x() {
        super.x();
    }
}

void main() {
    B b = new B();
    b.do_x();
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 12 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3500


Don <clugdbug yahoo.com.au> changed:

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


--- Comment #2 from Don <clugdbug yahoo.com.au> 2010-01-04 02:48:03 PST ---
This may be related to bug 2127.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 04 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3500


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |critical


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 18 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3500


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
            Version|2.035                       |1.00
            Summary|Program behaves differently |super behaves differently
                   |with -inline                |with -inline


--- Comment #3 from Don <clugdbug yahoo.com.au> 2010-02-03 00:19:21 PST ---
The thing that isn't working correctly is this line from the 'Expressions' page
in the spec: "If a member function is called with an explicit reference to
super, a non-virtual call is made." This bug applies to D1 as well (DMD1.00
fails).

Cause: direct calls are normally implemented in e2ir.c. If CallExp::toElem()
finds TOKsuper, it makes it a non-virtual call. But the direct call is a little
bit of a hack (there's a "//BUG: fix" comment in FuncExp::toElem()).

inline.c, SuperExp::doInline() changes it from 'super' to a variable, so e2ir
can't find it.
This patch disables inlining for direct 'super' calls. Allowing them to be
inlined would be a quite difficult, I think.


Index: inline.c
===================================================================
--- inline.c    (revision 362)
+++ inline.c    (working copy)
   -275,6 +275,10   

 int CallExp::inlineCost(InlineCostState *ics)
 {
+    // Bugzilla 3500: super.func() calls must be devirtualized, and the
inliner
+    // can't handle that at present.
+    if (e1->op == TOKdotvar && ((DotVarExp *)e1)->e1->op == TOKsuper)
+    return COST_MAX;
     return 1 + e1->inlineCost(ics) + arrayInlineCost(ics, arguments);
 }
-------------------------------------------------

Test case without any imports: 
--------------------------------
class A {
    void x() {  }
}

class B : A {
    override void x() {
        assert(0);
    }
    final void do_x() {
        super.x();
    }
}

void main() {
    B b = new B();
    b.do_x();
}
--------------------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 03 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3500


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com


--- Comment #4 from Walter Bright <bugzilla digitalmars.com> 2010-02-06
00:03:16 PST ---
changeset 373

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 06 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3500


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #5 from Walter Bright <bugzilla digitalmars.com> 2010-03-08
22:21:10 PST ---
Fixed dmd 1.057 and 2.041

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