D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9465 - Wrong code for delegate call
Summary: Wrong code for delegate call
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 critical
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2013-02-06 12:53 UTC by Maxim Fomin
Modified: 2014-07-29 17:20 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Maxim Fomin 2013-02-06 12:53:00 UTC
import std.stdio;

struct S
{
    int i;
    void bar()
    {
        ++i;
    }
    void foo() immutable
    {
        void delegate() dg1 = &bar;
        dg1(); // comment out to fix
        
        void delegate() dg2;
        dg2.ptr = cast(void*)&this;
        dg2.funcptr = cast(void function())&S.bar;
        dg2();
    }
}

void main()
{
    immutable S s;
    writeln(s.i);
    s.foo();
    writeln(s.i);
}

Without dg1() call, dmd arranges registers's content correctly. However in presence of dg1 call it incorrectly rearranges them so that [rex.W callq] calls this pointer, not function pointer.
Comment 1 yebblies 2014-07-29 17:20:07 UTC
This appears to work correctly now.