1068 – stack corruption with mixins and function templates

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1068 - stack corruption with mixins and function templates
Summary: stack corruption with mixins and function templates
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 All
: P2 critical
Assignee: Walter Bright
URL: http://www-users.mat.uni.torun.pl/~h3...
Keywords: wrong-code
Depends on:
Blocks:
Reported: 2007年03月19日 12:38 UTC by Tomasz Stachowiak
Modified: 2014年02月16日 15:23 UTC (History)
1 user (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Tomasz Stachowiak 2007年03月19日 12:38:10 UTC
When compiled as:
dmd Test.d Module.d, the resulting executable prints:
context: Module.Context 00900FE0
<context.func
thisptr: 00900FE0
str length: 540698740
str: 'Error: Access Violation
The addresses may vary, but generally random stack corruption happens with slight modifications to the source code. The correct output is:
context: Context 00A20FE0
<context.func
thisptr: 00A20FE0
str length: 1
str: 'a'
context.func>
returning from opCall
The correct executable can be obtained by compiling the program with earlier versions of DMD. I tried 0.175 and 1.0.
The error goes away when the order of modules is reversed at compilation, like 'dmd Module.d Test.d'.
It also happens with DMD 1.007, but doesnt happen with gdcWin 0.23 (@1.007).
Test files (as in bugzilla's 'URL'):
Module.d
---
template Mix() {
	static void foobar() {
		auto context = new Context;
		printf(`context: %.*s %0.8X`\n, context.toString, cast(void*)context);
		context.func!(typeof(this))();
		printf(`returning from opCall`\n);
	}
}
class Bar {
	mixin Mix;
}
void someFunc(char[] z) {
	printf(`str length: %d`\n, z.length);
	printf(`str: '%.*s'`\n, z);
}
class Context {
	void func(T)() {
		printf(`<context.func`\n);
		printf(`thisptr: %0.8X`\n, this);
		someFunc(`a`);
		printf(`context.func>`\n);
	}
}
---
Test.d
---
import Module;
class Foo {
	mixin Mix;
}
void main() {
	Bar.foobar();
}
---
Comment 1 Walter Bright 2007年04月16日 22:21:12 UTC
Fixed DMD 1.012
Comment 2 Thomas Kühne 2007年04月25日 12:48:34 UTC
Added to DStress as
http://dstress.kuehne.cn/run/t/template_62_A.d
http://dstress.kuehne.cn/run/t/template_62_B.d 


AltStyle によって変換されたページ (->オリジナル) /