[Issue 904] New: Bad code generated for local _assert routine

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 29 11:08:48 PST 2007


http://d.puremagic.com/issues/show_bug.cgi?id=904

           Summary: Bad code generated for local _assert routine
           Product: D
           Version: 1.00
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: sean at f4.ca


Given the code:

    extern (C) void _d_assert( char[] file, uint line );

    void call_assert( char[] file, uint line )
    {
        _d_assert( file, line );
    }

    void main()
    {
        call_assert( "a", 1 );
        assert( false );
    }

The code generation for call_assert and the automatically generated _assert
routine should be identical, but they aren't:

    _D4test11call_assertFAakZv      comdat
            assume  CS:_D4test11call_assertFAakZv
    L0:             push    EAX
                    push    dword ptr 0Ch[ESP]
                    push    dword ptr 0Ch[ESP]
                    call    near ptr __d_assert
                    add     ESP,0Ch
                    ret     8
    _D4test11call_assertFAakZv      ends
    _D4test8__assertFiZv    comdat
            assume  CS:_D4test8__assertFiZv
    L0:             push    EAX
                    push    dword ptr FLAT:_DATA[01Ch]
                    push    dword ptr FLAT:_DATA[018h]
                    call    near ptr __d_assert
                    ret
    _D4test8__assertFiZv    ends

You'll notice that the implicitly generated _assert routine doesn't clean up
its stack on exit.  This is fine for the normal case where an exception is
thrown from assert(), but any attempt to override _d_assert to behave otherwise
will resunt in an access violation.


-- 



More information about the Digitalmars-d-bugs mailing list