* explicitly name the fields we add in llvmgettemprecorddef()

* use those field names when loading their addresses in
    thlcgllvm.a_load_ref_cgpara()/gen_load_cgpara_loc(), instead of
    assuming the field indices in the llvm representation of those
    records matches the parameter location order (it currently does
    because we let llvm lay out C-packed records, but that will
    change)

git-svn-id: trunk@32713 -
This commit is contained in:
Jonas Maebe 2015-12-25 21:05:17 +00:00
parent 5774238887
commit f57a94b5aa
2 changed files with 11 additions and 18 deletions

View File

@ -189,16 +189,13 @@ implementation
procedure thlcgllvm.a_load_ref_cgpara(list: TAsmList; size: tdef; const r: treference; const cgpara: TCGPara); procedure thlcgllvm.a_load_ref_cgpara(list: TAsmList; size: tdef; const r: treference; const cgpara: TCGPara);
var var
tmpref, initialref, ref: treference; tmpref, initialref, ref: treference;
fielddef,
orgsize: tdef; orgsize: tdef;
tmpreg: tregister;
hloc: tlocation;
location: pcgparalocation; location: pcgparalocation;
orgsizeleft,
sizeleft, sizeleft,
totaloffset: asizeint; totaloffset: asizeint;
paralocidx: longint; paralocidx: longint;
userecord, userecord: boolean;
reghasvalue: boolean;
begin begin
location:=cgpara.location; location:=cgpara.location;
sizeleft:=cgpara.intsize; sizeleft:=cgpara.intsize;
@ -213,12 +210,10 @@ implementation
begin begin
if userecord then if userecord then
begin begin
{ llvmparadef is a record in this case, with every field corresponding { llvmparadef is a record in this case, with every field
to a single paraloc } corresponding to a single paraloc (fielddef is unused, because
paraloctoloc(location,hloc); it will be equivalent to location^.def -- see below) }
tmpreg:=getaddressregister(list,cpointerdef.getreusable(location^.def)); g_setup_load_field_by_name(list,trecorddef(size),'F'+tostr(paralocidx),initialref,tmpref,fielddef);
list.concat(taillvm.getelementptr_reg_size_ref_size_const(tmpreg,cpointerdef.getreusable(size),initialref,s32inttype,paralocidx,true));
reference_reset_base(tmpref,cpointerdef.getreusable(location^.def),tmpreg,0,newalignment(initialref.alignment,totaloffset));
end end
else else
tmpref:=initialref; tmpref:=initialref;
@ -1446,6 +1441,7 @@ implementation
hloc : tlocation; hloc : tlocation;
href, href2 : treference; href, href2 : treference;
hreg : tregister; hreg : tregister;
fielddef,
llvmparadef : tdef; llvmparadef : tdef;
index : longint; index : longint;
offset : pint; offset : pint;
@ -1479,15 +1475,11 @@ implementation
reference_reset_base(href,cpointerdef.getreusable(llvmparadef),hreg,0,destloc.reference.alignment); reference_reset_base(href,cpointerdef.getreusable(llvmparadef),hreg,0,destloc.reference.alignment);
end; end;
index:=0; index:=0;
offset:=0;
ploc:=para.location; ploc:=para.location;
repeat repeat
paraloctoloc(ploc,hloc); paraloctoloc(ploc,hloc);
hreg:=getaddressregister(list,cpointerdef.getreusable(ploc^.def)); g_setup_load_field_by_name(list,trecorddef(llvmparadef),'F'+tostr(index),href,href2,fielddef);
list.concat(taillvm.getelementptr_reg_size_ref_size_const(hreg,cpointerdef.getreusable(llvmparadef),href,s32inttype,index,true)); a_load_loc_ref(list,ploc^.def,fielddef,hloc,href2);
reference_reset_base(href2,cpointerdef.getreusable(ploc^.def),hreg,0,newalignment(href.alignment,offset));
a_load_loc_ref(list,ploc^.def,ploc^.def,hloc,href2);
inc(offset,ploc^.def.size);
inc(index); inc(index);
ploc:=ploc^.next; ploc:=ploc^.next;
until not assigned(ploc); until not assigned(ploc);

View File

@ -787,7 +787,8 @@ implementation
begin begin
res^.Data:=crecorddef.create_global_internal(typename,packrecords, res^.Data:=crecorddef.create_global_internal(typename,packrecords,
recordalignmin,maxcrecordalign); recordalignmin,maxcrecordalign);
trecorddef(res^.Data).add_fields_from_deflist(fieldtypes); for i:=0 to fieldtypes.count-1 do
trecorddef(res^.Data).add_field_by_def('F'+tostr(i),tdef(fieldtypes[i]));
end; end;
trecordsymtable(trecorddef(res^.Data).symtable).addalignmentpadding; trecordsymtable(trecorddef(res^.Data).symtable).addalignmentpadding;
result:=trecorddef(res^.Data); result:=trecorddef(res^.Data);