From ee014fa4ff9f00c17b9b587075b1326f26cb4a4d Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Tue, 29 Nov 2016 21:54:21 +0000 Subject: [PATCH] * fixed handling of typed files for LLVM when ISO-like I/O is active: encode the buffer in the type, and support typecasting the typed file to a different size (needed to be able to pass it to the compiler helpers that expected a "TypedFile", whose buffer is 0 bytes and which hence will always have a smaller size than the original type) (fixes test/tisoext1) git-svn-id: trunk@35017 - --- compiler/llvm/llvmdef.pas | 19 +++++++++++++++++-- compiler/llvm/nllvmcnv.pas | 11 ++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/compiler/llvm/llvmdef.pas b/compiler/llvm/llvmdef.pas index 943ce4295f..11e2975d5e 100644 --- a/compiler/llvm/llvmdef.pas +++ b/compiler/llvm/llvmdef.pas @@ -113,7 +113,7 @@ interface implementation uses - cutils,constexp, + globals,cutils,constexp, verbose,systems, fmodule, symtable,symconst,symsym, @@ -392,7 +392,22 @@ implementation case tfiledef(def).filetyp of ft_text : llvmaddencodedtype_intern(search_system_type('TEXTREC').typedef,[lef_inaggregate]+[lef_typedecl]*flags,encodedstr); - ft_typed, + ft_typed : + begin + { in case of ISO-like I/O, the typed file def includes a + get/put buffer of the size of the file's elements } + if (m_isolike_io in current_settings.modeswitches) and + not is_void(tfiledef(def).typedfiledef) then + encodedstr:=encodedstr+'<{'; + llvmaddencodedtype_intern(search_system_type('FILEREC').typedef,[lef_inaggregate]+[lef_typedecl]*flags,encodedstr); + if (m_isolike_io in current_settings.modeswitches) and + not is_void(tfiledef(def).typedfiledef) then + begin + encodedstr:=encodedstr+',['; + encodedstr:=encodedstr+tostr(tfiledef(def).typedfiledef.size); + encodedstr:=encodedstr+' x i8]}>' + end; + end; ft_untyped : llvmaddencodedtype_intern(search_system_type('FILEREC').typedef,[lef_inaggregate]+[lef_typedecl]*flags,encodedstr); else diff --git a/compiler/llvm/nllvmcnv.pas b/compiler/llvm/nllvmcnv.pas index 3f41308818..3dd21b02cc 100644 --- a/compiler/llvm/nllvmcnv.pas +++ b/compiler/llvm/nllvmcnv.pas @@ -236,7 +236,16 @@ procedure tllvmtypeconvnode.second_nothing; (resultdef.typ<>formaldef) and not is_open_array(resultdef) and not is_open_array(left.resultdef) and - (left.resultdef.size<>resultdef.size) then + (left.resultdef.size<>resultdef.size) and + { in case of ISO-like I/O, the typed file def includes a + get/put buffer of the size of the file's elements } + not( + (m_isolike_io in current_settings.modeswitches) and + (left.resultdef.typ=filedef) and + (tfiledef(left.resultdef).filetyp=ft_typed) and + (resultdef.typ=filedef) and + (tfiledef(resultdef).filetyp=ft_untyped) + ) then internalerror(2014012216); hlcg.location_force_mem(current_asmdata.CurrAsmList,left.location,left.resultdef); hreg:=hlcg.getaddressregister(current_asmdata.CurrAsmList,cpointerdef.getreusable(resultdef));