Procházet zdrojové kódy

* insert JVM checkcast instructions when a voidpointer is implicitly
converted to an incompatible type

git-svn-id: trunk@27744 -

Jonas Maebe před 11 roky
rodič
revize
2075bf157e

+ 1 - 0
.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/tprop2.pp svneol=native#text/plain
 tests/test/jvm/tprop3.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/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/tpvar.pp svneol=native#text/plain
 tests/test/jvm/tpvardelphi.pp svneol=native#text/plain
 tests/test/jvm/tpvardelphi.pp svneol=native#text/plain
 tests/test/jvm/tpvarglobal.pp svneol=native#text/plain
 tests/test/jvm/tpvarglobal.pp svneol=native#text/plain

+ 7 - 1
compiler/jvm/njvmcnv.pas

@@ -258,7 +258,13 @@ implementation
 
 
     function tjvmtypeconvnode.pass_1: tnode;
     function tjvmtypeconvnode.pass_1: tnode;
       begin
       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
           begin
             do_target_specific_explicit_typeconv(false,result);
             do_target_specific_explicit_typeconv(false,result);
             if assigned(result) then
             if assigned(result) then

+ 4 - 0
tests/test/jvm/testall.bat

@@ -290,3 +290,7 @@ echo " ** Compilation failed as expected"
 ppcjvm -O2 -g -B  toverload2
 ppcjvm -O2 -g -B  toverload2
 if %errorlevel% eq 0 exit /b 1
 if %errorlevel% eq 0 exit /b 1
 echo " ** Compilation failed as expected"
 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%

+ 2 - 0
tests/test/jvm/testall.sh

@@ -172,3 +172,5 @@ else
   echo " ** Compilation failed as expected"
   echo " ** Compilation failed as expected"
 fi
 fi
 set -e
 set -e
+$PPC -O2 -g -B -Sa tptrdynarr
+java -Dfile.encoding=UTF-8 -cp ../../../rtl/units/$RTLDIR:. tptrdynarr

+ 11 - 0
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.