Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Ticket #199 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

incorrect substruct initialization

Reported by: codekitchen Assigned to: lindquist
Priority: major Milestone:
Component: backend Version: hg tip
Keywords: struct Cc:

Description

The last assert in main() fails when compiled with LDC, but passes with GDC and DMD 1.x

If you uncomment the definition of Vertex.opCall, the assert passes.

struct Color {
    uint c;

}

struct Vertex {
    double x, y;
    Color c;
    /*static Vertex opCall(double x, double y, Color c) {*/
    /*    Vertex ret;*/
    /*    ret.x = x;*/
    /*    ret.y = y;*/
    /*    ret.c = c;*/
    /*    return ret;*/
    /*}*/
}

void main() {
    Color c = {0xffffffff};

    auto v = Vertex(1, 5, c);

    assert(v.x == 1 && v.y == 5); // passes
    assert(v.c.c == 0xffffffff);  // fails in LDC
}

Change History

02/01/09 07:43:58 changed by MattWhitworth

Bug exists in the latest ldc code. Here's a minimal test case:

struct Color {
    uint c;

}

struct Vertex {
    Color c;
}

void main() {
    Color c = {0xffffffff};

    auto v = Vertex(c);

    assert(v.c.c == 0xffffffff);  // fails in LDC
}

And here's the assembly generated after a plain compile:

08049590 <_Dmain>:
 8049590:       83 ec 2c                sub    $0x2c,%esp
 8049593:       c7 44 24 20 ff ff ff    movl   $0xffffffff,0x20(%esp)
 804959a:       ff 
 804959b:       c7 44 24 28 ff ff ff    movl   $0xffffffff,0x28(%esp)
 80495a2:       ff 
 80495a3:       8d 44 24 28             lea    0x28(%esp),%eax
 80495a7:       89 44 24 10             mov    %eax,0x10(%esp)
 80495ab:       89 44 24 18             mov    %eax,0x18(%esp)
 80495af:       83 f8 ff                cmp    $0xffffffff,%eax
 80495b2:       75 08                   jne    80495bc <_Dmain+0x2c>
 80495b4:       31 c0                   xor    %eax,%eax
 80495b6:       83 c4 2c                add    $0x2c,%esp
 80495b9:       c2 08 00                ret    $0x8
 80495bc:       8b 0d a4 1a 06 08       mov    0x8061aa4,%ecx
 80495c2:       89 4c 24 04             mov    %ecx,0x4(%esp)
 80495c6:       8b 0d a0 1a 06 08       mov    0x8061aa0,%ecx
 80495cc:       89 0c 24                mov    %ecx,(%esp)
 80495cf:       c7 44 24 08 0f 00 00    movl   $0xf,0x8(%esp)
 80495d6:       00 
 80495d7:       e8 24 00 00 00          call   8049600 <_d_assert>
 80495dc:       8d 74 26 00             lea    0x0(%esi,%eiz,1),%esi

02/01/09 14:42:43 changed by ChristianK

  • owner changed from ChristianK to lindquist.
  • version changed from release 0.9 to hg tip.
  • component changed from unspecified to backend.

Contrary to the commit message, this was not fixed in [913]. StructLiteralExp::toElem is wrong, the generated struct literal type is { { i32 }* } whereas the Vertex is { { i32 } }.

02/01/09 18:27:59 changed by lindquist

  • status changed from new to closed.
  • resolution set to fixed.

fixed in rev [915]

Copyright © 2008, LDC Development Team.