Bug 15921 – Win64: wrong codegen with array of structs slicing
Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2016-04-13T15:33:16Z
Last change time
2020-09-03T08:21:19Z
Keywords
backend, wrong-code
Assigned to
No Owner
Creator
ref2401
Comments
Comment #0 by refactor24 — 2016-04-13T15:33:16Z
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), 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 issue.
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 different.
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