From ef6dde6de305cff538f8cdd0bc4dca13c5574f4f Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Fri, 13 Sep 2019 19:06:40 +0000 Subject: [PATCH] * fixed loading the address of a copied labelnode in a loadnode (mantis #35877) git-svn-id: trunk@42987 - --- .gitattributes | 1 + compiler/nld.pas | 18 ++++++++++++- tests/test/units/rtl-generics/tw35877.pp | 33 ++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/test/units/rtl-generics/tw35877.pp diff --git a/.gitattributes b/.gitattributes index bc3714b67e..d4669f530c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -15514,6 +15514,7 @@ tests/test/units/matrix/tinv1.pp svneol=native#text/pascal tests/test/units/objects/testobj.pp svneol=native#text/plain tests/test/units/objects/testobj1.pp svneol=native#text/plain tests/test/units/objects/testobj2.pp svneol=native#text/plain +tests/test/units/rtl-generics/tw35877.pp svneol=native#text/plain tests/test/units/sharemem/libtest.pp svneol=native#text/plain tests/test/units/sharemem/test1.pp svneol=native#text/plain tests/test/units/softfpu/sfttst.pp svneol=native#text/plain diff --git a/compiler/nld.pas b/compiler/nld.pas index 913d1a1533..33aeddabb6 100644 --- a/compiler/nld.pas +++ b/compiler/nld.pas @@ -188,7 +188,7 @@ implementation defutil,defcmp, cpuinfo, htypechk,pass_1,procinfo,paramgr, - ncon,ninl,ncnv,nmem,ncal,nutils, + ncon,nflw,ninl,ncnv,nmem,ncal,nutils, cgbase ; @@ -273,12 +273,28 @@ implementation function tloadnode.dogetcopy : tnode; var n : tloadnode; + orglabel, + labelcopy : tlabelnode; begin n:=tloadnode(inherited dogetcopy); n.symtable:=symtable; n.symtableentry:=symtableentry; n.fprocdef:=fprocdef; n.loadnodeflags:=loadnodeflags; + if symtableentry.typ=labelsym then + begin + { see the comments for the tgotonode.labelsym field } + orglabel:=tlabelnode(tlabelsym(symtableentry).code); + labelcopy:=tlabelnode(orglabel.dogetcopy); + if not assigned(labelcopy.labsym) then + begin + if not assigned(orglabel.labsym) then + internalerror(2019091301); + labelcopy.labsym:=clabelsym.create('$copiedlabelfrom$'+orglabel.labsym.RealName); + labelcopy.labsym.code:=labelcopy; + end; + n.symtableentry:=labelcopy.labsym; + end; result:=n; end; diff --git a/tests/test/units/rtl-generics/tw35877.pp b/tests/test/units/rtl-generics/tw35877.pp new file mode 100644 index 0000000000..a94241fc3e --- /dev/null +++ b/tests/test/units/rtl-generics/tw35877.pp @@ -0,0 +1,33 @@ +program project1; + +{$mode objfpc}{$H+} + +uses + {$IFDEF UNIX} + cthreads, + {$ENDIF} + Classes + { you can add units after this } + , Generics.Collections; + +type + TSimpleRPCMessage2 = record + end; + TSimpleRPCResponse2 = record + R:array of TSimpleRPCMessage2; + end; + TResponses2 = specialize THashMap; + TSimpleRPCReqHandler2 = class(TInterfacedObject) + strict private + FResp:TResponses2; + procedure ReadResp(var R: TSimpleRPCResponse2); + end; + +procedure TSimpleRPCReqHandler2.ReadResp(var R: TSimpleRPCResponse2); +begin + R:=FResp.Items['123']; // throws project1.lpr(28,11) Error: Internal error 200510032 +end; + +begin +end. +