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

--- Comment #0 from Rainer Schuetze <> 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
__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:
------- You are receiving this mail because: -------

Reply via email to