From 9914f02faa29b1085c0f305e943eefc627581738 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Wed, 4 Nov 2015 20:46:10 +0000 Subject: [PATCH] * always set the resultdef for variant array constructors correctly, so we don't need to pull all kinds of special tricks pass_generate_code git-svn-id: trunk@32233 - --- compiler/ncgld.pas | 28 +++++++--------------------- compiler/nld.pas | 5 ++--- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/compiler/ncgld.pas b/compiler/ncgld.pas index 12c277035a..6a5f75af04 100644 --- a/compiler/ncgld.pas +++ b/compiler/ncgld.pas @@ -1118,7 +1118,6 @@ implementation href, fref : treference; lt : tdef; - realresult: tdef; paraloc : tcgparalocation; varvtypefield, varfield : tfieldvarsym; @@ -1135,22 +1134,12 @@ implementation dovariant:= ((nf_forcevaria in flags) or is_variant_array(resultdef)) and not(target_info.system in systems_managed_vm); + eledef:=tarraydef(resultdef).elementdef; + elesize:=eledef.size; if dovariant then - begin - eledef:=search_system_type('TVARREC').typedef; - varvtypefield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VTYPE')); - elesize:=eledef.size; - { in this case, the elementdef is set to "void", so create an - array of tvarrec instead } - realresult:=carraydef.getreusable(eledef,tarraydef(resultdef).highrange+1); - end + varvtypefield:=tfieldvarsym(search_struct_member_no_helper(trecorddef(eledef),'VTYPE')) else - begin - eledef:=tarraydef(resultdef).elementdef; - varvtypefield:=nil; - elesize:=tarraydef(resultdef).elesize; - realresult:=resultdef; - end; + varvtypefield:=nil; { alignment is filled in by tg.gethltemp below } location_reset_ref(location,LOC_CREFERENCE,OS_NO,0); fillchar(paraloc,sizeof(paraloc),0); @@ -1161,12 +1150,9 @@ implementation of the proper length to avoid getting unexpected results later -- allocating a temp of size 0 also forces it to be size 4 on regular targets } - if tarraydef(resultdef).highrange=-1 then - tg.gethltemp(current_asmdata.CurrAsmList,realresult,0,tt_normal,location.reference) - else - tg.gethltemp(current_asmdata.CurrAsmList,realresult,(tarraydef(resultdef).highrange+1)*elesize,tt_normal,location.reference); - href:=location.reference; - makearrayref(href,eledef); + tg.gethltemp(current_asmdata.CurrAsmList,resultdef,(tarraydef(resultdef).highrange+1)*elesize,tt_normal,location.reference); + href:=location.reference; + makearrayref(href,eledef); { Process nodes in array constructor } hp:=self; while assigned(hp) do diff --git a/compiler/nld.pas b/compiler/nld.pas index 8302d6a358..210fc7f21c 100644 --- a/compiler/nld.pas +++ b/compiler/nld.pas @@ -1143,9 +1143,8 @@ implementation hp:=tarrayconstructornode(hp.right); end; end; - { set the elementdef to the correct type in case of a managed - variant array } - if do_managed_variant then + { set the elementdef to the correct type in case of a variant array } + if do_variant then tarraydef(resultdef).elementdef:=search_system_type('TVARREC').typedef; expectloc:=LOC_CREFERENCE; end;