www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4631] New: const array literal rebuilt on every usage

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

           Summary: const array literal rebuilt on every usage
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: performance, wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: r.sagitario gmx.de


--- Comment #0 from Rainer Schuetze <r.sagitario gmx.de> 2010-08-12 00:52:32
PDT ---
This assertion in this code fails:

module test;

const int[] arr = [ 1, 2, 3 ];

void main()
{
    assert(arr.ptr == arr.ptr);
}

Here's the assembly for main:
__Dmain    comdat
    assume    CS:__Dmain
L0:        push    EBX
        push    ESI
        push    3
        push    2
        push    1
        push    3
        mov    EAX,offset FLAT:_D12TypeInfo_xAi6__initZ
        push    EAX
        call    near ptr __d_arrayliteralT
        add    ESP,014h
        mov    ECX,EAX
        mov    EBX,3
        push    ECX
        push    3
        push    2
        push    1
        push    3
        mov    EDX,offset FLAT:_D12TypeInfo_xAi6__initZ
        push    EDX
        call    near ptr __d_arrayliteralT
        add    ESP,014h
        mov    ECX,EAX
        mov    EAX,3
        mov    ESI,ECX
        pop    ECX
        cmp    ECX,ESI
        je    L4E
        mov    EAX,7
        call    near ptr _D4test8__assertFiZv
L4E:        xor    EAX,EAX
        pop    ESI
        pop    EBX
        ret
__Dmain    ends

The array literal is constructed on every use, even though the constant array
is written to the _DATA segment of the object file. I tried increasing the
array size if there is some threshold, but with about 50 elements it's still
the same. 

using "const(int)[] arr = [ 1, 2, 3 ];" works as expected.

This looks similar to bug 2237, but the code here works ok for D1 while bug
2237 is D1 only.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 12 2010
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4631


David Simcha <dsimcha yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |dsimcha yahoo.com
         Resolution|                            |DUPLICATE


--- Comment #1 from David Simcha <dsimcha yahoo.com> 2010-09-08 20:11:39 PDT ---
*** This issue has been marked as a duplicate of issue 4298 ***

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