From b50d0aa3d007670e304e0a34742e707961b825d5 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Mon, 23 Jul 2012 23:55:00 +0000 Subject: [PATCH] * only don't pre-finalize funcret temps that are passed by reference to the called function, fixes webtbs/tw3742.pp after r21955 (looked at wrong testsuite results :/ ) git-svn-id: trunk@21963 - --- compiler/nbas.pas | 6 +++++- compiler/ncal.pas | 5 +++++ compiler/ncgbas.pas | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/compiler/nbas.pas b/compiler/nbas.pas index 608b783862..2e20605040 100644 --- a/compiler/nbas.pas +++ b/compiler/nbas.pas @@ -140,7 +140,11 @@ interface { this temp only allows reading (makes it possible to safely use as reference under more circumstances) } - ti_readonly); + ti_readonly, + { if this is a managed temp, it doesn't have to be finalised before use + } + ti_nofini + ); ttempinfoflags = set of ttempinfoflag; const diff --git a/compiler/ncal.pas b/compiler/ncal.pas index 9308ab0c13..69271ec344 100644 --- a/compiler/ncal.pas +++ b/compiler/ncal.pas @@ -2392,6 +2392,11 @@ implementation (cnf_do_inline in callnodeflags) and not(tabstractvarsym(tprocdef(procdefinition).funcretsym).varregable in [vr_none,vr_addr])); include(temp.flags,nf_is_funcret); + { if a managed type is returned by reference, assigning something + to the result on the caller side will take care of decreasing + the reference count } + if paramanager.ret_in_param(resultdef,procdefinition.proccalloption) then + include(ttempcreatenode(temp).tempinfo^.flags,ti_nofini); add_init_statement(temp); { When the function result is not used in an inlined function we need to delete the temp. This can currently only be done by diff --git a/compiler/ncgbas.pas b/compiler/ncgbas.pas index 0ac7a51567..6480710651 100644 --- a/compiler/ncgbas.pas +++ b/compiler/ncgbas.pas @@ -407,7 +407,7 @@ interface { the temp could have been used previously either because the memory location was reused or because we're in a loop. In case it's used as a function result, that doesn't matter because it will be finalized when assigned to. } - if not(nf_is_funcret in flags) then + if not(ti_nofini in tempinfo^.flags) then hlcg.g_finalize(current_asmdata.CurrAsmList,tempinfo^.typedef,tempinfo^.location.reference); end else if (ti_may_be_in_reg in tempinfo^.flags) then