Bug 807 – inout params don't mesh with fpu

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2007-01-06T19:38:00Z
Last change time
2015-06-09T05:14:52Z
Assigned to
bugzilla
Creator
default_357-line

Comments

Comment #0 by default_357-line — 2007-01-06T19:38:25Z
http://paste.dprogramming.com/dpdd066k.php When putting inout real parameters directly on the floating point stack, doing stuff and popping them back, for some reason the parameter doesn't get changed. Verified on win32/mingw-gdc0.21svn and linux/dmd1.0 Update (5 minutes later) This is beyond odd. I've got an inout variable changing addresses. Replace the test function in the paste with void test(inout real r) { version(Tango) (new DisplayWriter(Cout))("Before: r is "c)(cast(int)cast(void*)&r)("\n"c)(); else writefln("Before: r is ")(cast(void*)(&r)); asm { fld r; fsin; fstp r; } version(Tango) (new DisplayWriter(Cout))("After: r is "c)(cast(int)cast(void*)&r)("\n"c)(); else writefln("After: r is ")(cast(void*)(&r)); } I got the following output: "Before: r is <someaddress>" "After: r is 0" Please enlighten me. Greetings
Comment #1 by bugzilla — 2007-02-02T03:16:25Z
inout parameters are passed by reference, i.e. they are actually a pointer. The sample code is using inline assembler, referencing the inout parameter. So, the inline assembler: void foo(inout real r) { asm { fld r; is actually loading a *pointer* and treating it as if it were a real. Inline assembler does exactly what you tell it to do. To make the above work, use instead: mov EAX,r ; fld real ptr [EAX] ; Not a compiler bug.