www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15921] New: Win64: wrong codegen with array of structs slicing


          Issue ID: 15921
           Summary: Win64: wrong codegen with array of structs slicing
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: refactor24 gmail.com

Array setting behaviour produces wrong results.

OS: Win 8.1 Pro
DMD: v2.071.0
Build-cmd: dmd main.d -ofconsole-app.exe -debug -unittest -g -wi -m64

module dmain;
import std.stdio;

struct Vec {
    float a;

void main(string[] args) {
    Vec[] array = new Vec[4];

    writeln("before: ", array); //  prints [Vec(nan), Vec(nan), Vec(nan),

    array[] = Vec(24);

    writeln("after: ", array); // prints [Vec(0), Vec(0), Vec(0), Vec(0)]

Seems like slicing is broken in general. All the following variations produce
different results but they are all wrong.
array[] = Vec(24);
array[0 .. 1] = Vec(24);
array[0 .. $] = Vec(24);

It works as expected if I do one of the following things:
1. Get rid of -m64. If I compile with -m32 flag then I cannot replicate the

2. Changing the type of the Vec.a field from float to real, int, uint, long,
ulong fixes the issue. Double still causes the issues.

3. Adding new fields to the Vec struct.

3.1. Vec {float a, b; } still does not work but the result is slightly
array[] = Vec(24, 5);
writeln("after: ", array); // [Vec(5, 0), Vec(5, 0), Vec(5, 0), Vec(5, 0)]

3.2. Vec { float a, b, c; } works fine.

4. Using index operator: array[0] = Vec(24) works fine

Apr 13 2016