Thread overview
[Issue 5974] New: Incorrect nested function address in expression (&f).ptr
May 10, 2011
Denis
Dec 21, 2011
Don
Jan 19, 2012
yebblies
May 10, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5974

           Summary: Incorrect nested function address in expression
                    (&f).ptr
           Product: D
           Version: D1 & D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: verylonglogin.reg@gmail.com


--- Comment #0 from Denis <verylonglogin.reg@gmail.com> 2011-05-09 23:46:44 PDT ---
Created an attachment (id=966)
Problem curious test case

Simple program:

void main()
{
    void f() { }

    void* t;

    t = (&f).ptr;
    //t = (&f).funcptr; //Uncommented: Error: &f is not an lvalue
}

First, look at lines 00402019 and 0040201E in disassembled main (dmd 1.067):

void main()
00402010  enter       4,0

    void* t;
00402014  xor         eax,eax
00402016  mov         dword ptr [t],eax

    t = (&f).ptr;
00402019  mov         ecx,offset main@main@f (402028h)
0040201E  mov         dword ptr [t],eax
00402021  xor         eax,eax
    //t = (&f).funcptr; //Uncommented: Error: &f is not an lvalue
}
00402023  leave
00402024  ret
00402025  int         3
00402026  int         3
00402027  int         3
{
    void f() { }
00402028  enter       4,0
0040202C  mov         dword ptr [ebp-4],eax
0040202F  leave
00402030  ret


Second, why "&f is not an lvalue" error occurs for "(&f).funcptr"? Maybe, I don't understand something?

Third, look at curiousTest.d attachment - it fails only if both asserts are uncommented.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 21, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5974


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

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


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2011-12-20 23:28:04 PST ---
More direct test case:

void main()
{
    void f() { }

    void* t1 = (&f).ptr;
    void* t2 = (&f).ptr;
    assert(t1 == t2);
}
The fac that (&f).funcptr fails to compile is a separate though closely related
bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 19, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5974


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies@gmail.com


--- Comment #2 from yebblies <yebblies@gmail.com> 2012-01-19 14:10:45 EST ---
(In reply to comment #0)
> Second, why "&f is not an lvalue" error occurs for "(&f).funcptr"? Maybe, I don't understand something?

iirc this fails because dmd rewrites dg.funcptr as *(cast(void**)(&dg)+1),
which naturally doesn't work on an rvalue.  The way to fix this is to rewrite
it as cast(void*)(cast(uint<64/128>)dg >> <32/64>), the same way array length
is accessed.

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