www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16381] New: Wrapping a float4 array leads to segfault.

https://issues.dlang.org/show_bug.cgi?id=16381

          Issue ID: 16381
           Summary: Wrapping a float4 array leads to segfault.
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: siudej gmail.com

This code leads to segfault in dmd:

module test;
import std.stdio;
import core.simd;

class Array
{
    float4[] arr;    
    this(size_t len)
    { 
        arr = new float4[len];
    }
    float4 opIndex(size_t idx)
    { 
        return arr[idx]; 
    }
}

unittest
{
    // without wrapper
    auto arr = new float4[50];
    float h = arr[0].ptr[0];

    // with wrapper
    auto arr2 = new Array(50);

    assert(typeid(arr[0]) == typeid(arr2[0]));
    // with intermediate
    float4 f4 = arr2[0];
    float f = f4.ptr[0];
    // without intermediate
    float g = arr2[0].ptr[0];
    writeln("done");
}

Run using: dmd -main -unittest test.d

Commenting `float g` line makes the code run. Typeid also shows the same type
for arr[0] and arr2[0], but the latter can be accessed only if saved to
intermediate float4.

--
Aug 12 2016