[Issue 4397] New: D1 const does not work

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jun 27 10:30:34 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4397

           Summary: D1 const does not work
           Product: D
           Version: D1 & D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: regression
          Priority: P1
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: nfxjfg at gmail.com


--- Comment #0 from nfxjfg at gmail.com 2010-06-27 10:30:32 PDT ---
In the following example, foo() will create an array literal on each call,
instead of returning a statically shared / compile time value. On D2, the same
may happen when using enum instead of const (I didn't test it).

In many cases, this codegen bug may go unnoticed, which makes it just worse.

$ cat rtz.d
struct X {
    int[] a;
}

const cX = X([1,2]);

X foo() {
    return cX;
}

$ dmd -c rtz.d
$ objdump -d -Mintel rtz.o -r
...
00000000 <_D3rtz3fooFZS3rtz1X>:
   0:   55                      push   ebp
   1:   8b ec                   mov    ebp,esp
   3:   83 ec 08                sub    esp,0x8
   6:   53                      push   ebx
   7:   6a 02                   push   0x2
   9:   6a 01                   push   0x1
   b:   6a 02                   push   0x2
   d:   b8 00 00 00 00          mov    eax,0x0
                        e: R_386_32     _D11TypeInfo_Ai6__initZ
  12:   50                      push   eax
  13:   e8 fc ff ff ff          call   14 <_D3rtz3fooFZS3rtz1X+0x14>
                        14: R_386_PC32  _d_arrayliteralT
  18:   89 c1                   mov    ecx,eax
  1a:   bb 02 00 00 00          mov    ebx,0x2
  1f:   89 5d f8                mov    DWORD PTR [ebp-0x8],ebx
  22:   89 4d fc                mov    DWORD PTR [ebp-0x4],ecx
  25:   8b 55 fc                mov    edx,DWORD PTR [ebp-0x4]
  28:   8b 45 f8                mov    eax,DWORD PTR [ebp-0x8]
  2b:   83 c4 10                add    esp,0x10
  2e:   5b                      pop    ebx
  2f:   c9                      leave  
  30:   c3                      ret

-- 
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