From f83f9168eec4b1da74619bde008502393be967b0 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Fri, 25 Dec 2015 21:05:26 +0000 Subject: [PATCH] * emit all resource strings and internal dynamic string data using the def representing that string type, instead of using p(wide)char o these string types are represented the same in llvm as p(wide)char, but this way we can check whether the emitted data type matches the expected one in the future git-svn-id: trunk@32715 - --- compiler/aasmcnst.pas | 18 +++++++++++++++++- compiler/cresstr.pas | 4 ++-- compiler/llvm/nllvmtcon.pas | 6 +++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/compiler/aasmcnst.pas b/compiler/aasmcnst.pas index b1a6834c25..5080d78d6c 100644 --- a/compiler/aasmcnst.pas +++ b/compiler/aasmcnst.pas @@ -299,6 +299,7 @@ type protected procedure maybe_emit_tail_padding(def: tdef); virtual; function emit_string_const_common(stringtype: tstringtype; len: asizeint; encoding: tstringencoding; var startlab: tasmlabel):tasmlabofs; + function get_dynstring_def_for_type(stringtype: tstringtype; winlikewidestring: boolean): tstringdef; procedure begin_aggregate_internal(def: tdef; anonymous: boolean); virtual; procedure end_aggregate_internal(def: tdef; anonymous: boolean); virtual; { when building an anonymous record, we cannot immediately insert the @@ -1280,6 +1281,21 @@ implementation end; + function ttai_typedconstbuilder.get_dynstring_def_for_type(stringtype: tstringtype; winlikewidestring: boolean): tstringdef; + begin + if stringtype=st_ansistring then + result:=tstringdef(cansistringtype) + else if (stringtype=st_unicodestring) or + ((stringtype=st_widestring) and + not winlikewidestring) then + result:=tstringdef(cunicodestringtype) + else if stringtype=st_widestring then + result:=tstringdef(cwidestringtype) + else + internalerror(2015122101); + end; + + procedure ttai_typedconstbuilder.begin_aggregate_internal(def: tdef; anonymous: boolean); var info: taggregateinformation; @@ -1468,7 +1484,7 @@ implementation procedure ttai_typedconstbuilder.emit_string_offset(const ll: tasmlabofs; const strlength: longint; const st: tstringtype; const winlikewidestring: boolean; const charptrdef: tdef); begin - emit_tai(Tai_const.Create_sym_offset(ll.lab,ll.ofs),charptrdef); + emit_tai(Tai_const.Create_sym_offset(ll.lab,ll.ofs),get_dynstring_def_for_type(st,winlikewidestring)); end; diff --git a/compiler/cresstr.pas b/compiler/cresstr.pas index 723dc9c970..63f1e41c17 100644 --- a/compiler/cresstr.pas +++ b/compiler/cresstr.pas @@ -147,8 +147,8 @@ uses tcb.maybe_begin_aggregate(resstrdef); namelab:=tcb.emit_ansistring_const(current_asmdata.asmlists[al_const],@current_module.localsymtable.name^[1],length(current_module.localsymtable.name^),getansistringcodepage); tcb.emit_string_offset(namelab,length(current_module.localsymtable.name^),st_ansistring,false,charpointertype); - tcb.emit_tai(tai_const.create_nil_dataptr,voidpointertype); - tcb.emit_tai(tai_const.create_nil_dataptr,voidpointertype); + tcb.emit_tai(tai_const.create_nil_dataptr,cansistringtype); + tcb.emit_tai(tai_const.create_nil_dataptr,cansistringtype); tcb.emit_ord_const(0,u32inttype); tcb.maybe_end_aggregate(resstrdef); current_asmdata.asmlists[al_resourcestrings].concatList( diff --git a/compiler/llvm/nllvmtcon.pas b/compiler/llvm/nllvmtcon.pas index b04f33fa89..3e4af562fd 100644 --- a/compiler/llvm/nllvmtcon.pas +++ b/compiler/llvm/nllvmtcon.pas @@ -322,6 +322,7 @@ implementation srsym : tsym; srsymtable: tsymtable; strrecdef : trecorddef; + strdef: tdef; offset: pint; field: tfieldvarsym; dataptrdef: tdef; @@ -349,7 +350,10 @@ implementation field:=trecordsymtable(strrecdef.symtable).findfieldbyoffset(offset); { pointerdef to the string data array } dataptrdef:=cpointerdef.getreusable(field.vardef); - queue_init(charptrdef); + { the fields of the resourcestring record are declared as ansistring } + strdef:=get_dynstring_def_for_type(st,winlikewidestring); + queue_init(strdef); + queue_typeconvn(charptrdef,strdef); queue_subscriptn(strrecdef,field); queue_emit_asmsym(ll.lab,strrecdef); end