[Issue 1068] New: stack corruption with mixins and function templates
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Mar 19 10:38:23 PDT 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1068
Summary: stack corruption with mixins and function templates
Product: D
Version: 1.009
Platform: PC
URL: http://www-users.mat.uni.torun.pl/~h3r3tic/bug.zip
OS/Version: Windows
Status: NEW
Keywords: wrong-code
Severity: critical
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: h3r3tic at mat.uni.torun.pl
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();
}
---
--
More information about the Digitalmars-d-bugs
mailing list