Browse Source

* convert array indices always to s32int, because that is the index type used
by java arrays (otherwise we may get unwanted sign extensions after
performing e.g. an s16bit operation, see the test)

git-svn-id: trunk@26472 -

Jonas Maebe 11 years ago
parent
commit
a5653916e0
3 changed files with 14 additions and 0 deletions
  1. 8 0
      compiler/jvm/njvmmem.pas
  2. 4 0
      tests/test/jvm/testall.bat
  3. 2 0
      tests/test/jvm/testall.sh

+ 8 - 0
compiler/jvm/njvmmem.pas

@@ -427,6 +427,14 @@ implementation
              object instances (since that's what they are in Java) }
              object instances (since that's what they are in Java) }
            right.resultdef:=s32inttype;
            right.resultdef:=s32inttype;
            right.location.size:=OS_S32;
            right.location.size:=OS_S32;
+          end
+        else if (right.location.loc<>LOC_CONSTANT) and
+                ((right.resultdef.typ<>orddef) or
+                 (torddef(right.resultdef).ordtype<>s32bit)) then
+          begin
+            { Java array indices are always 32 bit signed integers }
+            hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,s32inttype,true);
+            right.resultdef:=s32inttype;
           end;
           end;
 
 
         { adjust index if necessary }
         { adjust index if necessary }

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

@@ -280,3 +280,7 @@ ppcjvm -O2 -g -B  -CTinitlocals tinitvar
 if %errorlevel% neq 0 exit /b %errorlevel%
 if %errorlevel% neq 0 exit /b %errorlevel%
 javaa -Dfile.encoding=UTF-8 -cp ..\..\..\rtl\units\jvm-java;. org.freepascal.test.tinitvar.tinitvar
 javaa -Dfile.encoding=UTF-8 -cp ..\..\..\rtl\units\jvm-java;. org.freepascal.test.tinitvar.tinitvar
 if %errorlevel% neq 0 exit /b %errorlevel%
 if %errorlevel% neq 0 exit /b %errorlevel%
+ppcjvm -O2 -g -B  -CTinitlocals tsmallintarr
+if %errorlevel% neq 0 exit /b %errorlevel%
+javaa -Dfile.encoding=UTF-8 -cp ..\..\..\rtl\units\jvm-java;. tsmallintarr
+if %errorlevel% neq 0 exit /b %errorlevel%

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

@@ -156,3 +156,5 @@ javac -encoding utf-8 -cp ../../../rtl/units/$RTLDIR:. tjavalowercaseproc.java
 java -Dfile.encoding=UTF-8 -cp ../../../rtl/units/$RTLDIR:. tjavalowercaseproc
 java -Dfile.encoding=UTF-8 -cp ../../../rtl/units/$RTLDIR:. tjavalowercaseproc
 $PPC -O2 -g -B -Sa -CTinitlocals tinitvar
 $PPC -O2 -g -B -Sa -CTinitlocals tinitvar
 java -Dfile.encoding=UTF-8 -cp ../../../rtl/units/$RTLDIR:. org.freepascal.test.tinitvar.tinitvar
 java -Dfile.encoding=UTF-8 -cp ../../../rtl/units/$RTLDIR:. org.freepascal.test.tinitvar.tinitvar
+$PPC -O2 -g -B -Sa tsmallintarr
+java -Dfile.encoding=UTF-8 -cp ../../../rtl/units/$RTLDIR:. tsmallintarr