Browse Source

* fix tcgvecnode.update_reference_reg_packed if OS_INT<>OS_ADDR

git-svn-id: trunk@30659 -
florian 10 years ago
parent
commit
e791f534d2
1 changed files with 18 additions and 4 deletions
  1. 18 4
      compiler/ncgmem.pas

+ 18 - 4
compiler/ncgmem.pas

@@ -673,8 +673,8 @@ implementation
            internalerror(200608051);
          sref.ref := location.reference;
          hreg := cg.getaddressregister(current_asmdata.CurrAsmList);
-         cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SUB,OS_INT,tarraydef(left.resultdef).lowrange,maybe_const_reg,hreg);
-         cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_IMUL,OS_INT,l,hreg);
+         cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SUB,OS_ADDR,tarraydef(left.resultdef).lowrange,maybe_const_reg,hreg);
+         cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_IMUL,OS_ADDR,l,hreg);
          { keep alignment for index }
          sref.ref.alignment := left.resultdef.alignment;
          if not ispowerof2(packedbitsloadsize(l),temp) then
@@ -692,8 +692,22 @@ implementation
              cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_ADD,OS_ADDR,sref.ref.base,offsetreg);
              sref.ref.base := offsetreg;
            end;
-         cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_AND,OS_INT,(1 shl (3+alignpower))-1,hreg);
-         sref.bitindexreg := hreg;
+
+         { the if expression below is a constant evaluated at compile time, so disable the unreachable code
+           warning }
+{$push}
+{$warn 6018 off}
+         { we can reuse hreg only if OS_INT and OS_ADDR have the same size/type }
+         if OS_INT<>OS_ADDR then
+           begin
+             sref.bitindexreg := cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
+             cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_INT,hreg,sref.bitindexreg);
+           end
+         else
+           sref.bitindexreg:=hreg;
+{$pop}
+
+         cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_AND,OS_INT,(1 shl (3+alignpower))-1,sref.bitindexreg);
          sref.startbit := 0;
          sref.bitlen := resultdef.packedbitsize;
          if (left.location.loc = LOC_REFERENCE) then