915 – dmd generate bad form return(retn 4) for invariant func

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 915 - dmd generate bad form return(retn 4) for invariant func
Summary: dmd generate bad form return(retn 4) for invariant func
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P1 critical
Assignee: Walter Bright
URL:
Keywords:
Depends on:
Blocks:
Reported: 2007年02月01日 07:55 UTC by david
Modified: 2014年02月16日 15:25 UTC (History)
0 users

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 david 2007年02月01日 07:55:32 UTC
import std.stdio;
interface IUnknown{
	extern(Windows):
	void func();
}
class ComObject :IUnknown
{
extern (Windows):
	void func()
	{writefln(`comobject`);
	}
}
interface IDataObject: IUnknown
{
	extern(Windows):
	void method();
}
package class invarianttest:ComObject, IDataObject
{
	invariant
	{
		writefln(`hello invariant`);
	}
extern (Windows):
	override void func()
	{
	int esp;
	asm{
		mov esp,ESP;
	}
	printf("\n%d",esp);
	printf(`func`);
	}
	void method()
	{
		writefln(`method`);
	}
}
void main()
{
	auto inst= new invarianttest;
	int esp;
	asm{
		mov esp,ESP;
	}
	inst.func();
	inst.method();
	writefln("\n%d",esp);
	asm{
		mov esp,ESP;
	}
	writefln("\n%d",esp);
}
we get runtime AV when the we return from our own invariant to _d_invariant
the problem is dmd generate the retn 4 for the return of our own invariant func
Comment 1 david 2007年02月01日 08:54:04 UTC
a simpler case, but we don't see any exception get caught. 
de-comment the ret , we can see the code work correctly.
though i find in some situation , the case actually in a ctor
before calling my invariant , dmd first push some thing on the stack
and the windows directive makes it seems right( that's quite weird)
 and the next time calling my invariant in my case, it's 
from _d_invariant, the situation is different , _d_invariant need 
the invariant func retn directly instead of "retn 4".
import std.stdio;
package class invarianttest
{
	extern(D):
	this(Object test,int i)
	{
		myobject = test;
		writefln(`class tester`,i);
	}
	extern(Windows):
	invariant
	{
		writefln(`hello invariant`);
		asm
		{
//			ret;
		}
	}
	
extern (Windows):
	void func()
	{
		printf(`func`);
	}
	void method()
	{
		writefln(`method`);
	}
	extern(D):
	private:
	Object myobject;
}
void main()
{
	Object t=new Object;
	auto inst= new invarianttest(t,1);
	inst.func();
	inst.method();
}
Comment 2 Walter Bright 2007年02月12日 03:45:52 UTC
Fixed DMD 1.005


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