www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7720] New: asm silent wrong code generation

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7720

           Summary: asm silent wrong code generation
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: deadalnix gmail.com



See code blow :

static uint globalThreadLocal = 123456;

uint foo() {
    asm {
        naked;
        mov EAX, globalThreadLocal;
        ret;
    }
}

void main() {
    uint x = foo();

    import std.stdio;
    writeln(x);
}

Output garbage. This code should generate an error and not compile as if it was
correct.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 17 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7720


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com



It's not that simple.  IIRC "mov EAX, globalThreadLocal" moves the offset of
globalThreadLocal into EAX.  While this obviously isn't what you expected, this
is valid and useful.  How else would you get the offset?

After all, you're using the inline assembler.  The compiler will never be able
to protect you against writing incorrect assembly.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 17 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7720





 It's not that simple.  IIRC "mov EAX, globalThreadLocal" moves the offset of
 globalThreadLocal into EAX.  While this obviously isn't what you expected, this
 is valid and useful.  How else would you get the offset?
 
 After all, you're using the inline assembler.  The compiler will never be able
 to protect you against writing incorrect assembly.
In this case, this behavior should be documented. But this is confusing, because it is not what happen with other variables (variable value is copied into the register). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 18 2012