digitalmars.D.bugs - [Issue 16087] New: Alignment (.alignof) and stack space incorrect
- via Digitalmars-d-bugs (48/48) May 28 2016 https://issues.dlang.org/show_bug.cgi?id=16087
https://issues.dlang.org/show_bug.cgi?id=16087 Issue ID: 16087 Summary: Alignment (.alignof) and stack space incorrect for SIMD types. Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Keywords: SIMD, wrong-code Severity: blocker Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: Marco.Leise gmx.de The following code compiled and run with dmd-2.071 prints: SIMD vector types inherit their base type's alignment: float8.alignof yields 4 but should yield 32. void16.alignof yields 1 but should yield 16. When embedded, a float4 exposes some hidden alignment, as it changes to 16. The float8 needs a 32 byte alignment though or we SEGFAULT as soon as we load c[0] or c[1]. Even worse, the stack space occupied by these 32 byte vectors is only 16! ------------------------- void main() { import core.simd; import std.stdio; import std.math; union Matrix4x4 { float[16] a; float4[4] b; float8[2] c; alias a this; } float8 onStackA; float8 onStackB; writeln("SIMD vector types inherit their base type's alignment:"); writefln("float8.alignof yields %s but should yield 32.", float8.alignof); writefln("void16.alignof yields %s but should yield 16.", void16.alignof); writefln("When embedded, a float4 exposes some hidden alignment, as it changes to %s.", Matrix4x4.alignof); writeln("The float8 needs a 32 byte alignment though or we SEGFAULT as soon as we load c[0] or c[1]."); writefln("Even worse, the stack space occupied by these %s byte vectors is only %s!", float8.sizeof, abs(cast(ptrdiff_t)&onStackB - cast(ptrdiff_t)&onStackA)); } ------------------------- Compiled programs with too little stack space or incorrect alignment of SIMD types crash. --
May 28 2016