[Issue 12588] New: Segfault on X86_64 assigning std.complex to array
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Apr 16 03:06:26 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=12588
Issue ID: 12588
Summary: Segfault on X86_64 assigning std.complex to array
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: major
Priority: P1
Component: DMD
Assignee: nobody at puremagic.com
Reporter: kevin.lamonte at gmail.com
Encountered this working on a templated matrix library at
https://github.com/klamonte/eng. Here is a reduced test case:
----
import std.conv;
import std.complex;
import std.stdio;
public class foo(T) {
private T [] data;
public this(size_t length, T item) {
data = new T[length];
version (X86_64) {
static if ((is(T == Complex!(float))) ||
(is(T == Complex!(double))) ||
(is(T == Complex!(real)))
) {
for (auto i = 0; i < data.length; i++) {
data[i] = to!(T)(item);
}
} else {
data[0 .. $] = to!(T)(item);
}
} else {
data[0 .. $] = to!(T)(item);
}
}
}
unittest {
auto test = new foo!(Complex!(double))(20, Complex!(double)(3, -4));
stdout.writefln("test %s", test.data[10]);
auto test2 = new foo!(float)(20, 1.23);
stdout.writefln("test2 %s", test2.data[10]);
}
public void main() {
stdout.writeln("Hello.");
}
----
Normal output via 'dmd -unittest test.d -oftest ; ./test':
----
test 3-4i
test2 1.23
Hello.
----
Remove the version(X86_64) guard so that the line 'data[0 .. $] =
to!(T)(item);' executes when T is Complex, and the output is:
----
Segmentation fault
----
Either the 'data[0 .. $] = ...'code path is broken when the compiler emits
64-bit, or the same code path is only working accidentally on 32-bit and it
should have failed to compile. I'm not 100% sure which.
Also: the severity help text does not define the differences between normal,
major, critical, etc. Feel free to change as needed, obviously I can
workaround this issue in my code.
--
More information about the Digitalmars-d-bugs
mailing list