D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 234 - dynamic arrays in combination with SSE instructions cause segment faults
Summary: dynamic arrays in combination with SSE instructions cause segment faults
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Linux
: P2 normal
Assignee: Walter Bright
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2006-07-02 09:09 UTC by Thomas Kühne
Modified: 2021-05-27 12:58 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Thomas Kühne 2006-07-02 09:09:27 UTC
If compiled with -version=dynamic, the code below segmentfaults.

import std.stdio;

int main(){
	version(dynamic){
		double[] a = new double[2];
		double[] b = new double[2];
	}else{
		double[2] a;
		double[2] b;
	}
		
	a[0] = 4.0;
	a[1] = 2.0;

	b[0] = -0.5;
	b[1] = -0.25;

	writefln("a:\t%s\t%s", a[0], a[1]);
	writefln("b:\t%s\t%s", b[0], b[1]);

	asm{
		movupd XMM0, a;
		movupd b, XMM0;
		emms;
	}
	writefln("-- asm finished --");
	
	writefln("a:\t%s\t%s", a[0], a[1]);
	writefln("b:\t%s\t%s", b[0], b[1]);

	return 0;
}

test cases:
http://dstress.kuehne.cn/run/o/odd_bug_05_A.d
http://dstress.kuehne.cn/run/o/odd_bug_05_B.d
http://dstress.kuehne.cn/run/o/odd_bug_05_C.d
http://dstress.kuehne.cn/run/o/odd_bug_05_D.d
Comment 1 Walter Bright 2006-12-12 04:03:14 UTC
It segment faults because dynamic arrays are stored differently than static arrays. When using inline asm, one must account for this. For the dynamic arrays, using the following will work:

asm{
        mov EAX,a+4;
        movupd XMM0, [EAX];
        mov EAX,b+4;
        movupd [EAX], XMM0;
        emms;
}
Comment 2 Dlang Bot 2021-05-27 12:58:17 UTC
dlang/dlang-bot pull request #271 "Fixes so far" was merged into master:

- b0d4e55c19dc65b82920751bd4d1cc54194ba24d by Vladimir Panteleev:
  dlangbot: Add support for draft pull requests
  
  Fixes #234.

https://github.com/dlang/dlang-bot/pull/271