Bug 8778 – Struct with core.simd type has wrong size and gives Segmentation fault

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-07T22:08:00Z
Last change time
2016-04-25T06:46:11Z
Keywords
ice, SIMD
Assigned to
nobody
Creator
malteskarupke

Comments

Comment #0 by malteskarupke — 2012-10-07T22:08:58Z
I have this problem in version 2.060 (but I had to select 2.041 because that's the newest version in the bug tracker) I'm also not sure whether this should be two bugs or one, but they seem related so I'm posting them as one. I wanted to write a Vector4 struct which gives operator overloads for simple SIMD instructions. But the compiler behaves weird in that a) the struct has the wrong size, and b) it gives me segmentation faults if I make the struct pure nothrow @safe. void main() { import core.simd; struct PureVector4 { pure: nothrow: @safe: PureVector4 opAdd(in PureVector4 rhs) const { PureVector4 toReturn; toReturn.xyzw = __simd(XMM.ADDPS, xyzw, rhs.xyzw); return toReturn; } float4 xyzw; } struct Vector4 { Vector4 opAdd(in Vector4 rhs) const { Vector4 toReturn; toReturn.xyzw = __simd(XMM.ADDPS, xyzw, rhs.xyzw); return toReturn; } float4 xyzw; } static assert(PureVector4.sizeof == Vector4.sizeof); // doesn't compile the pure one is size 16 (correct), the other one is size 32 (incorrect) PureVector4 vec; // Segmentation fault. would work with the non-pure one vec.xyzw.array = [1, 2, 3, 1]; // just need to use the vector from the previous line, otherwise there is no Segmentation fault }
Comment #1 by clugdbug — 2012-10-08T06:05:55Z
(In reply to comment #0) > I have this problem in version 2.060 (but I had to select 2.041 because that's > the newest version in the bug tracker) Those specific version numbers are obsolete. Just use "D1", "D2", or "D1 & D2".
Comment #2 by malteskarupke — 2012-10-08T12:25:14Z
One more comment: I can also get the non-pure Vector4 to segfault by doing this for example: Vector4 a; a.xyzw.array = [1, 2, 3, 4]; Vector4 b = a + a + a + a + a + a; // segfault. probably alignment issue for one of the temporaries Should I create a separate bug for this or should I keep these as one ticket?
Comment #3 by bugzilla — 2016-04-25T06:46:11Z
I can't reproduce the errors described with the current compiler. But I also suspect you should make the structs 'static'. Non-static structs declared in a function have a hidden extra field added which is a dynamic link to the enclosing function's stack frame.