From 2075bf157ee5149517d17df4ac75c913d2ab667a Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Sat, 10 May 2014 12:47:34 +0000 Subject: [PATCH] * insert JVM checkcast instructions when a voidpointer is implicitly converted to an incompatible type git-svn-id: trunk@27744 - --- .gitattributes | 1 + compiler/jvm/njvmcnv.pas | 8 +++++++- tests/test/jvm/testall.bat | 4 ++++ tests/test/jvm/testall.sh | 2 ++ tests/test/jvm/tptrdynarr.pp | 11 +++++++++++ 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/test/jvm/tptrdynarr.pp diff --git a/.gitattributes b/.gitattributes index d1a8f17a59..30d2eb4ddf 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10897,6 +10897,7 @@ tests/test/jvm/tprop.pp svneol=native#text/plain tests/test/jvm/tprop2.pp svneol=native#text/plain tests/test/jvm/tprop3.pp svneol=native#text/plain tests/test/jvm/tprop4.pp svneol=native#text/plain +tests/test/jvm/tptrdynarr.pp svneol=native#text/plain tests/test/jvm/tpvar.pp svneol=native#text/plain tests/test/jvm/tpvardelphi.pp svneol=native#text/plain tests/test/jvm/tpvarglobal.pp svneol=native#text/plain diff --git a/compiler/jvm/njvmcnv.pas b/compiler/jvm/njvmcnv.pas index 0565ce2f2b..3d4d21821d 100644 --- a/compiler/jvm/njvmcnv.pas +++ b/compiler/jvm/njvmcnv.pas @@ -258,7 +258,13 @@ implementation function tjvmtypeconvnode.pass_1: tnode; begin - if (nf_explicit in flags) then + if (nf_explicit in flags) or + { some implicit type conversions from voidpointer to other types + (such as dynamic array) are allowed too, even though the types are + incompatible -> make sure we check those too and insert checkcast + instructions as necessary } + (is_voidpointer(left.resultdef) and + not is_voidpointer(resultdef)) then begin do_target_specific_explicit_typeconv(false,result); if assigned(result) then diff --git a/tests/test/jvm/testall.bat b/tests/test/jvm/testall.bat index 5e3acf3dc7..3dea723a5b 100644 --- a/tests/test/jvm/testall.bat +++ b/tests/test/jvm/testall.bat @@ -290,3 +290,7 @@ echo " ** Compilation failed as expected" ppcjvm -O2 -g -B toverload2 if %errorlevel% eq 0 exit /b 1 echo " ** Compilation failed as expected" +ppcjvm -O2 -g -B -CTinitlocals tptrdynarr +if %errorlevel% neq 0 exit /b %errorlevel% +java -Dfile.encoding=UTF-8 -cp ..\..\..\rtl\units\jvm-java;. tptrdynarr +if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/tests/test/jvm/testall.sh b/tests/test/jvm/testall.sh index 69e0af2967..ef55845aba 100755 --- a/tests/test/jvm/testall.sh +++ b/tests/test/jvm/testall.sh @@ -172,3 +172,5 @@ else echo " ** Compilation failed as expected" fi set -e +$PPC -O2 -g -B -Sa tptrdynarr +java -Dfile.encoding=UTF-8 -cp ../../../rtl/units/$RTLDIR:. tptrdynarr diff --git a/tests/test/jvm/tptrdynarr.pp b/tests/test/jvm/tptrdynarr.pp new file mode 100644 index 0000000000..e63ecc4939 --- /dev/null +++ b/tests/test/jvm/tptrdynarr.pp @@ -0,0 +1,11 @@ +{$mode delphi} + +program tptrdynarr; + +var + p: pointer; + a: array of byte; +begin + p:=nil; + a:=p; +end.