Thread overview
[Issue 2350] New: Contracts with a naked body are indecent
Sep 09, 2008
d-bugmail
Sep 04, 2011
Stewart Gordon
Sep 05, 2011
Don
September 09, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2350

           Summary: Contracts with a naked body are indecent
           Product: D
           Version: 1.034
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P4
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: clugdbug@yahoo.com.au


It seems that in/out contracts assume that a stack frame has been set up. This is not true for naked functions, so bad code is generated. Ideally, if the body contains the keyword 'naked', in/out contracts should create and destroy a stack frame.

----
void rude(int a)
in {
        assert(a==1);
}
body {
        asm { naked; }
}

void main() {
        rude(1);
}


-- 

September 04, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=2350


Stewart Gordon <smjg@iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg@iname.com


--- Comment #1 from Stewart Gordon <smjg@iname.com> 2011-09-04 15:39:44 PDT ---
In which case, what would "naked" do?  If nothing, the compiler ought to disallow it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 05, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=2350



--- Comment #2 from Don <clugdbug@yahoo.com.au> 2011-09-05 00:23:54 PDT ---
(In reply to comment #1)
> In which case, what would "naked" do?  If nothing, the compiler ought to disallow it.

For non-naked functions, the contracts don't set up a stack frame, because the
function already does it. The generated code is:
 push EBP;
 mov EBP, ESP;
 <run in contract>
 <run function body>
 <run out contract>
 pop EBP;

If no contracts are present, or with -release, the generated code is currently:
 <run naked body>
which is correct.

But if contracts are present, and not in a release build, the code is:
 <run in contract>
 <run naked body>
 <run out contract>
which causes a crash. Correct behaviour would be:

 push EBP;
 mov EBP, ESP;
 <run in contract>
 pop EBP;
 <run naked body>
 push EBP;
 mov EBP, ESP;
 <run out contract>
 pop EBP;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------