[Issue 4631] New: const array literal rebuilt on every usage
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Aug 12 00:52:34 PDT 2010
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 at puremagic.com
ReportedBy: r.sagitario at gmx.de
--- Comment #0 from Rainer Schuetze <r.sagitario at 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: -------
More information about the Digitalmars-d-bugs
mailing list