Kaynağa Gözat

* fixed indexing dynamic arrays and strings with a constant index (the index
was ignored in this case)

git-svn-id: trunk@32741 -

Jonas Maebe 9 yıl önce
ebeveyn
işleme
fad7c8f151
1 değiştirilmiş dosya ile 15 ekleme ve 5 silme
  1. 15 5
      compiler/llvm/nllvmmem.pas

+ 15 - 5
compiler/llvm/nllvmmem.pas

@@ -106,6 +106,7 @@ implementation
       locref: preference;
       locref: preference;
       hreg: tregister;
       hreg: tregister;
       arrptrelementdef: tdef;
       arrptrelementdef: tdef;
+      indirect: boolean;
 
 
     procedure getarrelementptrdef;
     procedure getarrelementptrdef;
       begin
       begin
@@ -137,17 +138,24 @@ implementation
       locref:=nil;
       locref:=nil;
       { avoid uninitialised warning }
       { avoid uninitialised warning }
       arrptrelementdef:=nil;
       arrptrelementdef:=nil;
-      if not arraytopointerconverted and
-         not is_dynamicstring(left.resultdef) and
-         not is_dynamic_array(left.resultdef) then
+      indirect:=
+        not is_dynamicstring(left.resultdef) and
+        not is_dynamic_array(left.resultdef);
+      if (not arraytopointerconverted and
+          indirect) or
+         (constarrayoffset<>0) then
         begin
         begin
           { the result is currently a pointer to left.resultdef (the array type)
           { the result is currently a pointer to left.resultdef (the array type)
              -> convert it into a pointer to an element inside this array }
              -> convert it into a pointer to an element inside this array }
           getarrelementptrdef;
           getarrelementptrdef;
           hreg:=hlcg.getaddressregister(current_asmdata.CurrAsmList,arrptrelementdef);
           hreg:=hlcg.getaddressregister(current_asmdata.CurrAsmList,arrptrelementdef);
           locref^:=thlcgllvm(hlcg).make_simple_ref(current_asmdata.CurrAsmList,location.reference,left.resultdef);
           locref^:=thlcgllvm(hlcg).make_simple_ref(current_asmdata.CurrAsmList,location.reference,left.resultdef);
-          current_asmdata.CurrAsmList.Concat(taillvm.getelementptr_reg_size_ref_size_const(hreg,cpointerdef.getreusable(left.resultdef),
-            locref^,ptruinttype,constarrayoffset,true));
+          if indirect then
+            current_asmdata.CurrAsmList.Concat(taillvm.getelementptr_reg_size_ref_size_const(hreg,cpointerdef.getreusable(left.resultdef),
+              locref^,ptruinttype,constarrayoffset,true))
+          else
+            current_asmdata.CurrAsmList.Concat(taillvm.getelementptr_reg_size_ref_size_const(hreg,left.resultdef,
+              locref^,ptruinttype,constarrayoffset,false));
           reference_reset_base(locref^,hreg,0,locref^.alignment);
           reference_reset_base(locref^,hreg,0,locref^.alignment);
         end;
         end;
 
 
@@ -175,6 +183,7 @@ implementation
           hreg:=hlcg.getintregister(current_asmdata.CurrAsmList,ptruinttype);
           hreg:=hlcg.getintregister(current_asmdata.CurrAsmList,ptruinttype);
           hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_ADD,ptruinttype,constarrayoffset,maybe_const_reg,hreg);
           hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_ADD,ptruinttype,constarrayoffset,maybe_const_reg,hreg);
           maybe_const_reg:=hreg;
           maybe_const_reg:=hreg;
+          constarrayoffset:=0;
         end;
         end;
       hreg:=hlcg.getaddressregister(current_asmdata.CurrAsmList,cpointerdef.getreusable(resultdef));
       hreg:=hlcg.getaddressregister(current_asmdata.CurrAsmList,cpointerdef.getreusable(resultdef));
       location.reference:=thlcgllvm(hlcg).make_simple_ref(current_asmdata.CurrAsmList,location.reference,left.resultdef);
       location.reference:=thlcgllvm(hlcg).make_simple_ref(current_asmdata.CurrAsmList,location.reference,left.resultdef);
@@ -226,6 +235,7 @@ implementation
       sref.ref:=location.reference;
       sref.ref:=location.reference;
       hreg:=hlcg.getintregister(current_asmdata.CurrAsmList,ptruinttype);
       hreg:=hlcg.getintregister(current_asmdata.CurrAsmList,ptruinttype);
       hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SUB,ptruinttype,tarraydef(left.resultdef).lowrange-constarrayoffset,maybe_const_reg,hreg);
       hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SUB,ptruinttype,tarraydef(left.resultdef).lowrange-constarrayoffset,maybe_const_reg,hreg);
+      constarrayoffset:=0;
 
 
       { keep alignment for index }
       { keep alignment for index }
       sref.ref.alignment:=left.resultdef.alignment;
       sref.ref.alignment:=left.resultdef.alignment;