From d2a7f17d8c9308e060c7a3fe0755f4de3639a395 Mon Sep 17 00:00:00 2001 From: svenbarth Date: Sat, 23 Jan 2016 22:19:00 +0000 Subject: [PATCH] Fix for Mantis #29372. compiler/ncgcal.pas: * tchcallnode.release_para_temps: don't release temps of a constructor's self parameter + added test git-svn-id: trunk@32990 - --- .gitattributes | 1 + compiler/ncgcal.pas | 9 +++++++- tests/webtbs/tw29372.pp | 49 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/webtbs/tw29372.pp diff --git a/.gitattributes b/.gitattributes index c84aca3980..ebea4124a3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -14921,6 +14921,7 @@ tests/webtbs/tw2926.pp svneol=native#text/plain tests/webtbs/tw2927.pp svneol=native#text/plain tests/webtbs/tw29321.pp svneol=native#text/pascal tests/webtbs/tw29353.pp -text svneol=native#text/plain +tests/webtbs/tw29372.pp svneol=native#text/pascal tests/webtbs/tw2942a.pp svneol=native#text/plain tests/webtbs/tw2942b.pp svneol=native#text/plain tests/webtbs/tw2943.pp svneol=native#text/plain diff --git a/compiler/ncgcal.pas b/compiler/ncgcal.pas index 3e05f53fa1..fd3cf64af4 100644 --- a/compiler/ncgcal.pas +++ b/compiler/ncgcal.pas @@ -625,7 +625,14 @@ implementation begin { don't release the funcret temp } if not(assigned(ppn.parasym)) or - not(vo_is_funcret in ppn.parasym.varoptions) then + not( + (vo_is_funcret in ppn.parasym.varoptions) or + ( + (vo_is_self in ppn.parasym.varoptions) and + (procdefinition.proctypeoption=potype_constructor) and + (ppn.parasym.vardef.typ<>objectdef) + ) + )then location_freetemp(current_asmdata.CurrAsmList,ppn.left.location); { process also all nodes of an array of const } hp:=ppn.left; diff --git a/tests/webtbs/tw29372.pp b/tests/webtbs/tw29372.pp new file mode 100644 index 0000000000..8360aee067 --- /dev/null +++ b/tests/webtbs/tw29372.pp @@ -0,0 +1,49 @@ +program tw29372; + +{$MODE DELPHI} +type + TR1 = record + A, B, C: Int64; + constructor Create(_A, _B, _C: Int64); + end; + + TR2 = record + D, E, F: Int64; + constructor Create(_D, _E, _F: Int64); + end; + + constructor TR1.Create(_A, _B, _C: Int64); + begin + A := _A; + B := _B; + C := _C; + end; + + constructor TR2.Create(_D, _E, _F: Int64); + begin + D := _D; + E := _E; + F := _F; + end; + +{ Note: unlike in the file attached at #29372 we use "const" both times to + trigger the error on x86_64 as well } +procedure Foo(const _1: TR1; const _2: TR2); +begin + if _1.A <> 1 then + Halt(1); + if _1.B <> 2 then + Halt(2); + if _1.C <> 3 then + Halt(3); + if _2.D <> 4 then + Halt(2); + if _2.E <> 5 then + Halt(5); + if _2.F <> 6 then + Halt(6); +end; + +begin + Foo(TR1.Create(1, 2, 3), TR2.Create(4,5,6)); +end.