浏览代码

* replace assigned(dynarray) and dynarray=/<>nil with length(dynarray)=/<>0
on the JVM target because empty dynarrays are not always nil there

git-svn-id: branches/jvmbackend@19154 -

Jonas Maebe 14 年之前
父节点
当前提交
583c9a3360
共有 7 个文件被更改,包括 67 次插入3 次删除
  1. 1 0
      .gitattributes
  2. 18 1
      compiler/jvm/njvmadd.pas
  3. 18 1
      compiler/jvm/njvminl.pas
  4. 8 1
      compiler/ninl.pas
  5. 16 0
      tests/test/jvm/tdynarrnil.pp
  6. 4 0
      tests/test/jvm/testall.bat
  7. 2 0
      tests/test/jvm/testall.sh

+ 1 - 0
.gitattributes

@@ -9781,6 +9781,7 @@ tests/test/jvm/tcnvstr3.pp svneol=native#text/plain
 tests/test/jvm/tconst.pp svneol=native#text/plain
 tests/test/jvm/tconst.pp svneol=native#text/plain
 tests/test/jvm/tdefpara.pp svneol=native#text/plain
 tests/test/jvm/tdefpara.pp svneol=native#text/plain
 tests/test/jvm/tdynarrec.pp svneol=native#text/plain
 tests/test/jvm/tdynarrec.pp svneol=native#text/plain
+tests/test/jvm/tdynarrnil.pp svneol=native#text/plain
 tests/test/jvm/tenum.pp svneol=native#text/plain
 tests/test/jvm/tenum.pp svneol=native#text/plain
 tests/test/jvm/test.pp -text svneol=native#text/plain
 tests/test/jvm/test.pp -text svneol=native#text/plain
 tests/test/jvm/testall.bat -text svneol=native#application/x-bat
 tests/test/jvm/testall.bat -text svneol=native#application/x-bat

+ 18 - 1
compiler/jvm/njvmadd.pas

@@ -61,7 +61,7 @@ interface
       aasmtai,aasmdata,aasmcpu,defutil,
       aasmtai,aasmdata,aasmcpu,defutil,
       hlcgobj,hlcgcpu,cgutils,
       hlcgobj,hlcgcpu,cgutils,
       cpupara,
       cpupara,
-      nbas,ncon,nset,nadd,ncal,ncnv,nld,nmat,nmem,
+      nbas,ncon,nset,nadd,ncal,ncnv,ninl,nld,nmat,nmem,
       njvmcon,
       njvmcon,
       cgobj;
       cgobj;
 
 
@@ -92,6 +92,23 @@ interface
             result:=jvm_first_addset;
             result:=jvm_first_addset;
             exit;
             exit;
           end;
           end;
+        { special handling for comparing a dynamic array to nil: dynamic arrays
+          can be empty on the jvm target and not be different from nil at the
+          same time (array of 0 elements) -> change into length check }
+        if is_dynamic_array(left.resultdef) and
+           (right.nodetype=niln) then
+          begin
+           result:=caddnode.create(nodetype,cinlinenode.create(in_length_x,false,left),genintconstnode(0));
+           left:=nil;
+           exit;
+          end;
+        if is_dynamic_array(right.resultdef) and
+           (left.nodetype=niln) then
+          begin
+            result:=caddnode.create(nodetype,cinlinenode.create(in_length_x,false,right),genintconstnode(0));
+            right:=nil;
+            exit;
+          end;
         result:=inherited pass_1;
         result:=inherited pass_1;
         if expectloc=LOC_FLAGS then
         if expectloc=LOC_FLAGS then
           expectloc:=LOC_JUMP;
           expectloc:=LOC_JUMP;

+ 18 - 1
compiler/jvm/njvminl.pas

@@ -37,6 +37,7 @@ interface
           function typecheck_new(var handled: boolean): tnode;
           function typecheck_new(var handled: boolean): tnode;
 
 
           function first_copy: tnode; override;
           function first_copy: tnode; override;
+          function first_assigned: tnode; override;
 
 
           function first_box: tnode; override;
           function first_box: tnode; override;
           function first_unbox: tnode; override;
           function first_unbox: tnode; override;
@@ -74,7 +75,7 @@ implementation
       aasmbase,aasmtai,aasmdata,aasmcpu,
       aasmbase,aasmtai,aasmdata,aasmcpu,
       symtype,symconst,symdef,symsym,symtable,jvmdef,
       symtype,symconst,symdef,symsym,symtable,jvmdef,
       defutil,
       defutil,
-      nbas,ncon,ncnv,nmem,ncal,nld,nflw,nutils,
+      nadd,nbas,ncon,ncnv,nmem,ncal,nld,nflw,nutils,
       cgbase,pass_1,pass_2,
       cgbase,pass_1,pass_2,
       cpuinfo,ncgutil,
       cpuinfo,ncgutil,
       cgutils,hlcgobj,hlcgcpu;
       cgutils,hlcgobj,hlcgcpu;
@@ -224,6 +225,22 @@ implementation
       end;
       end;
 
 
 
 
+    function tjvminlinenode.first_assigned: tnode;
+      begin
+        { on the JVM target, empty arrays can also be <> nil but have length 0
+          instead. Since assigned(dynarray) is only used to determine whether
+          the length is <> 0 on other targets, replace this expression here }
+        if is_dynamic_array(tcallparanode(left).left.resultdef) then
+          begin
+            result:=caddnode.create(unequaln,cinlinenode.create(
+              in_length_x,false,tcallparanode(left).left),genintconstnode(0));
+            tcallparanode(left).left:=nil;
+          end
+        else
+          result:=inherited;
+      end;
+
+
     function tjvminlinenode.first_box: tnode;
     function tjvminlinenode.first_box: tnode;
       var
       var
         boxdef,
         boxdef,

+ 8 - 1
compiler/ninl.pas

@@ -75,6 +75,7 @@ interface
           function first_length: tnode; virtual;
           function first_length: tnode; virtual;
           function first_box: tnode; virtual; abstract;
           function first_box: tnode; virtual; abstract;
           function first_unbox: tnode; virtual; abstract;
           function first_unbox: tnode; virtual; abstract;
+          function first_assigned: tnode; virtual;
 
 
         private
         private
           function handle_str: tnode;
           function handle_str: tnode;
@@ -3000,7 +3001,7 @@ implementation
 
 
           in_assigned_x:
           in_assigned_x:
             begin
             begin
-              expectloc := LOC_JUMP;
+              result:=first_assigned;
             end;
             end;
 
 
           in_pred_x,
           in_pred_x,
@@ -3612,6 +3613,12 @@ implementation
           end;
           end;
        end;
        end;
 
 
+     function tinlinenode.first_assigned: tnode;
+       begin
+         result:=nil;
+         expectloc := LOC_JUMP;
+       end;
+
      function tinlinenode.handle_box: tnode;
      function tinlinenode.handle_box: tnode;
        begin
        begin
          result:=nil;
          result:=nil;

+ 16 - 0
tests/test/jvm/tdynarrnil.pp

@@ -0,0 +1,16 @@
+program tdynarrnil;
+
+var
+  arr: array of longint;
+begin
+  setlength(arr,0);
+  if assigned(arr) then
+    halt(1);
+  if arr<>nil then
+    halt(2);
+  setlength(arr,1);
+  if not assigned(arr) then
+    halt(3);
+  if arr=nil then
+    halt(4);
+end.

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

@@ -216,4 +216,8 @@ ppcjvm -O2 -g -B tw20212
 if %errorlevel% neq 0 exit /b %errorlevel%
 if %errorlevel% neq 0 exit /b %errorlevel%
 java -Dfile.encoding=UTF-8 -cp ..\..\..\rtl\units\jvm-java;. tw20212
 java -Dfile.encoding=UTF-8 -cp ..\..\..\rtl\units\jvm-java;. tw20212
 if %errorlevel% neq 0 exit /b %errorlevel%
 if %errorlevel% neq 0 exit /b %errorlevel%
+ppcjvm -O2 -g -B tdynarrnil
+if %errorlevel% neq 0 exit /b %errorlevel%
+java -Dfile.encoding=UTF-8 -cp ..\..\..\rtl\units\jvm-java;. tdynarrnil
+if %errorlevel% neq 0 exit /b %errorlevel%
 
 

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

@@ -118,3 +118,5 @@ $PPC -O2 -g -B tstr
 java -Dfile.encoding=UTF-8 -cp ../../../rtl/units/jvm-java:. tstr
 java -Dfile.encoding=UTF-8 -cp ../../../rtl/units/jvm-java:. tstr
 $PPC -O2 -g -B tw20212 
 $PPC -O2 -g -B tw20212 
 java -Dfile.encoding=UTF-8 -cp ../../../rtl/units/jvm-java:. tw20212
 java -Dfile.encoding=UTF-8 -cp ../../../rtl/units/jvm-java:. tw20212
+$PPC -O2 -g -B tdynarrnil
+java -Dfile.encoding=UTF-8 -cp ../../../rtl/units/jvm-java:. tdynarrnil