From fcb128c66c59857692564184b2d4dc9714657985 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Tue, 23 Jan 2007 16:49:59 +0000 Subject: [PATCH] * don't trash reference counted types with -gt (mantis 8183) git-svn-id: trunk@6149 - --- .gitattributes | 1 + compiler/ncgutil.pas | 10 ++++++---- tests/webtbs/tw8183.pp | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 tests/webtbs/tw8183.pp diff --git a/.gitattributes b/.gitattributes index 07d10138a1..6c1e816e75 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7991,6 +7991,7 @@ tests/webtbs/tw8150a.pp svneol=native#text/plain tests/webtbs/tw8150d.pp svneol=native#text/plain tests/webtbs/tw8155.pp svneol=native#text/plain tests/webtbs/tw8156.pp svneol=native#text/plain +tests/webtbs/tw8183.pp svneol=native#text/plain tests/webtbs/ub1873.pp svneol=native#text/plain tests/webtbs/ub1883.pp svneol=native#text/plain tests/webtbs/uw0555.pp svneol=native#text/plain diff --git a/compiler/ncgutil.pas b/compiler/ncgutil.pas index 5f2fd7866a..7bf9ad1409 100644 --- a/compiler/ncgutil.pas +++ b/compiler/ncgutil.pas @@ -963,9 +963,10 @@ implementation trashintval: aint; list: TAsmList absolute arg; begin - if (tsym(p).typ=localvarsym) or - ((tsym(p).typ=paravarsym) and - (vo_is_funcret in tparavarsym(p).varoptions)) then + if ((tsym(p).typ=localvarsym) or + ((tsym(p).typ=paravarsym) and + (vo_is_funcret in tparavarsym(p).varoptions))) and + not(tabstractnormalvarsym(p).vardef.needs_inittable) then begin trashintval := trashintvalues[localvartrashing]; case tabstractnormalvarsym(p).initialloc.loc of @@ -1140,7 +1141,6 @@ implementation if (tsym(p).typ=paravarsym) then begin needs_inittable := - not is_class_or_interface(tparavarsym(p).vardef) and tparavarsym(p).vardef.needs_inittable; case tparavarsym(p).varspez of vs_value : @@ -1158,6 +1158,7 @@ implementation cg.a_load_loc_reg(list,OS_ADDR,tparavarsym(p).initialloc,tmpreg); reference_reset_base(href,tmpreg,0); if (localvartrashing <> -1) and + not(needs_inittable) and { needs separate implementation to trash open arrays } { since their size is only known at run time } not is_special_array(tparavarsym(p).vardef) then @@ -1167,6 +1168,7 @@ implementation end; end; else if (localvartrashing <> -1) and + not(needs_inittable) and ([vo_is_funcret,vo_is_hidden_para] * tparavarsym(p).varoptions = [vo_is_funcret,vo_is_hidden_para]) then begin tmpreg:=cg.getaddressregister(list); diff --git a/tests/webtbs/tw8183.pp b/tests/webtbs/tw8183.pp new file mode 100644 index 0000000000..1ac0d215a6 --- /dev/null +++ b/tests/webtbs/tw8183.pp @@ -0,0 +1,21 @@ +{ %opt=-gt } + +program test; + +{$MODE OBJFPC} + +type + xstr = interface(iunknown) end; + +operator := (a: integer): xstr; +begin + if ptruint(result) <> ptruint(nil) then + halt(1); + pointer(result) := nil; +end; + +var + x: xstr; +begin + x := 42; +end.