* when assigning a value to a temp marked as ti_const, do not immediately

release the source location in case it was also a temp. Reason: we
    don't increase reference counts when assigning to a ti_const (they are
    like const parameters), so the original value must stay alive until
    the ti_const temp is freed
   o free the original data in the ttempdelete node for the ti_const temp
   o don't increase reference counts when assigning composite types to
     ti_const temps either

git-svn-id: trunk@34287 -
This commit is contained in:
Jonas Maebe 2016-08-12 13:35:51 +00:00
parent a3ca471d32
commit 18580d3069
4 changed files with 23 additions and 2 deletions

View File

@ -153,7 +153,12 @@ interface
}
ti_nofini,
{ the value described by this temp. node is const/immutable, this is important for
managed types like ansistrings where temp. refs are pointers to the actual value }
managed types like ansistrings where temp. refs are pointers to the actual value
-- in this case, assignments to the temp do not increase the
reference count, and if the assigned value was a temp itself then
that temp is not deallocated until this temp is deleted (since
otherwise the assigned value may be freed before the last use of
the temp) }
ti_const
);
ttempinfoflags = set of ttempinfoflag;

View File

@ -540,6 +540,19 @@ interface
location_reset(location,LOC_VOID,OS_NO);
{ see comments at ti_const declaration: if we initialised this temp with
the value of another temp, that other temp was not freed because the
ti_const flag was set }
if (ti_const in tempinfo^.flags) and
assigned(tempinfo^.tempinitcode) then
begin
if tempinfo^.tempinitcode.nodetype<>assignn then
internalerror(2016081201);
if tbinarynode(tempinfo^.tempinitcode).right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
tg.ungetiftemp(current_asmdata.CurrAsmList,tbinarynode(tempinfo^.tempinitcode).right.location.reference);
end;
case tempinfo^.location.loc of
LOC_REFERENCE:
begin

View File

@ -703,7 +703,9 @@ implementation
exit;
end;
releaseright:=true;
releaseright:=
(left.nodetype<>temprefn) or
not(ti_const in ttemprefnode(left).tempinfo^.flags);
{ shortstring assignments are handled separately }
if is_shortstring(left.resultdef) then

View File

@ -809,6 +809,7 @@ implementation
(left.resultdef.typ in [arraydef,objectdef,recorddef]) and
not is_interfacecom_or_dispinterface(left.resultdef) and
not is_dynamic_array(left.resultdef) and
not is_const(left) and
not(target_info.system in systems_garbage_collected_managed_types) then
begin
hp:=ccallparanode.create(caddrnode.create_internal(