Bug 2350 – Contracts with a naked body are indecent

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2008-09-09T02:50:00Z
Last change time
2015-07-01T08:08:22Z
Keywords
contracts, pull, wrong-code
Assigned to
nobody
Creator
clugdbug

Comments

Comment #0 by clugdbug — 2008-09-09T02:50:05Z
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); }
Comment #1 by smjg — 2011-09-04T15:39:44Z
In which case, what would "naked" do? If nothing, the compiler ought to disallow it.
Comment #2 by clugdbug — 2011-09-05T00:23:54Z
(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;
Comment #3 by yebblies — 2014-08-31T13:41:25Z
Comment #4 by github-bugzilla — 2014-09-01T23:30:39Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/a643c1e8380d4faaa182f016b70b1c50bdddca16 Issue 2350 - Contracts with a naked body are indecent Error on a naked function with contracts instead of generating wrong code https://github.com/D-Programming-Language/dmd/commit/eee87f646bc48ac0e59f354ae11d0f5a79e205ba Merge pull request #3937 from yebblies/issue2350 Issue 2350 - Contracts with a naked body are indecent
Comment #5 by yebblies — 2014-09-02T05:34:07Z
wrong-code keyword now applies to D1 only.
Comment #6 by k.hara.pg — 2015-07-01T08:08:22Z
D1 is retired, so close as resolved fixed in D2.