Przeglądaj źródła

* 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 -

Jonas Maebe 16 lat temu
rodzic
commit
966ebbf157
4 zmienionych plików z 35 dodań i 2 usunięć
  1. 1 0
      .gitattributes
  2. 14 1
      compiler/defutil.pas
  3. 8 1
      compiler/ncnv.pas
  4. 12 0
      tests/webtbs/tw13820.pp

+ 1 - 0
.gitattributes

@@ -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

+ 14 - 1
compiler/defutil.pas

@@ -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

+ 8 - 1
compiler/ncnv.pas

@@ -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 - 0
tests/webtbs/tw13820.pp

@@ -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.