* fixed missing reference counting in case a refcounted type was implicitly

type casted to a non-refcounted type, e.g. dynarray to pointer in Delphi
    mode (mantis #13820)

git-svn-id: trunk@13195 -
This commit is contained in:
Jonas Maebe 2009-05-25 19:41:14 +00:00
parent 17a7903e60
commit 966ebbf157
4 changed files with 35 additions and 2 deletions

1
.gitattributes vendored
View File

@ -8873,6 +8873,7 @@ tests/webtbs/tw1375.pp svneol=native#text/plain
tests/webtbs/tw1376.pp svneol=native#text/plain
tests/webtbs/tw13763.pp svneol=native#text/plain
tests/webtbs/tw13815.pp svneol=native#text/plain
tests/webtbs/tw13820.pp svneol=native#text/plain
tests/webtbs/tw1398.pp svneol=native#text/plain
tests/webtbs/tw1401.pp svneol=native#text/plain
tests/webtbs/tw1407.pp svneol=native#text/plain

View File

@ -88,10 +88,14 @@ interface
}
function is_signed(def : tdef) : boolean;
{# Returns true whether def_from's range is comprised in def_to's if both are
{# Returns whether def_from's range is comprised in def_to's if both are
orddefs, false otherwise }
function is_in_limit(def_from,def_to : tdef) : boolean;
{# Returns whether def is reference counted }
function is_refcounted_type(def: tdef) : boolean;
{ function is_in_limit_value(val_from:TConstExprInt;def_from,def_to : tdef) : boolean;}
{*****************************************************************************
@ -492,6 +496,15 @@ implementation
end;
end;
function is_refcounted_type(def: tdef): boolean;
begin
result:=
def.needs_inittable and
not is_class(def);
end;
{ true, if p points to an open array def }
function is_open_string(p : tdef) : boolean;
begin

View File

@ -1667,7 +1667,14 @@ implementation
{ Only leave when there is no conversion to do.
We can still need to call a conversion routine,
like the routine to convert a stringconstnode }
if convtype in [tc_equal,tc_not_possible] then
if (convtype in [tc_equal,tc_not_possible]) and
{ some conversions, like dynarray to pointer in Delphi
mode, must not be removed, because then we get memory
leaks due to missing temp finalization }
(not is_refcounted_type(left.resultdef) or
{ different kinds of refcounted types may need calls
to different kinds of refcounting helpers }
(resultdef=left.resultdef)) then
begin
left.resultdef:=resultdef;
if (nf_explicit in flags) and (left.nodetype = addrn) then

12
tests/webtbs/tw13820.pp Normal file
View File

@ -0,0 +1,12 @@
{ %opt=-gh }
program copytest;
var
S, D : array of Integer;
begin
HaltOnNotReleased := true;
SetLength(S,4000);
D := Copy(Copy(S));
end.