diff --git a/compiler/i386/n386cal.pas b/compiler/i386/n386cal.pas index e47e1f3c94..4ebe0c0514 100644 --- a/compiler/i386/n386cal.pas +++ b/compiler/i386/n386cal.pas @@ -91,12 +91,6 @@ implementation paramanager.ret_in_param(procdefinition.returndef,procdefinition.proccalloption) then inc(pop_size,sizeof(aint)); - { Safecall generates a hidden return value, which is always passed } - { in eax. So there is nothing to remove from the stack. } - if (tf_safecall_exceptions in target_info.flags) and - (procdefinition.proccalloption=pocall_safecall) then - inc(pop_size,sizeof(aint)); - { better than an add on all processors } if pop_size=4 then begin diff --git a/compiler/ncgcal.pas b/compiler/ncgcal.pas index d7fb59be7f..7f83d3b987 100644 --- a/compiler/ncgcal.pas +++ b/compiler/ncgcal.pas @@ -838,8 +838,13 @@ implementation begin pop_size:=pushedparasize; { for Cdecl functions we don't need to pop the funcret when it - was pushed by para } - if paramanager.ret_in_param(procdefinition.returndef,procdefinition.proccalloption) then + was pushed by para. Except for safecall functions with + safecall-exceptions enabled. In that case the funcret is always + returned as a para which is considered a normal para on the + c-side, so the funcret has to be pop'ed normally. } + if not ((procdefinition.proccalloption=pocall_safecall) and + (tf_safecall_exceptions in target_info.flags)) and + paramanager.ret_in_param(procdefinition.returndef,procdefinition.proccalloption) then dec(pop_size,sizeof(pint)); { Remove parameters/alignment from the stack } pop_parasize(pop_size);