Browse Source

* correctly handle static arrays with a lower index <> 0
+ added test

git-svn-id: trunk@46901 -

svenbarth 4 years ago
parent
commit
2c372071fd
3 changed files with 50 additions and 1 deletions
  1. 1 0
      .gitattributes
  2. 1 1
      compiler/ncnv.pas
  3. 48 0
      tests/test/tarrconstr16.pp

+ 1 - 0
.gitattributes

@@ -14405,6 +14405,7 @@ tests/test/tarrconstr12.pp svneol=native#text/pascal
 tests/test/tarrconstr13.pp svneol=native#text/pascal
 tests/test/tarrconstr13.pp svneol=native#text/pascal
 tests/test/tarrconstr14.pp svneol=native#text/pascal
 tests/test/tarrconstr14.pp svneol=native#text/pascal
 tests/test/tarrconstr15.pp svneol=native#text/pascal
 tests/test/tarrconstr15.pp svneol=native#text/pascal
+tests/test/tarrconstr16.pp svneol=native#text/pascal
 tests/test/tarrconstr2.pp svneol=native#text/pascal
 tests/test/tarrconstr2.pp svneol=native#text/pascal
 tests/test/tarrconstr3.pp svneol=native#text/pascal
 tests/test/tarrconstr3.pp svneol=native#text/pascal
 tests/test/tarrconstr4.pp svneol=native#text/pascal
 tests/test/tarrconstr4.pp svneol=native#text/pascal

+ 1 - 1
compiler/ncnv.pas

@@ -2119,7 +2119,7 @@ implementation
               cassignmentnode.create(
               cassignmentnode.create(
                 cvecnode.create(
                 cvecnode.create(
                   ctemprefnode.create(arrnode),
                   ctemprefnode.create(arrnode),
-                  cordconstnode.create(paracount,tarraydef(totypedef).rangedef,false)),
+                  cordconstnode.create(paracount+tarraydef(totypedef).lowrange,tarraydef(totypedef).rangedef,false)),
                 elemnode.left));
                 elemnode.left));
             elemnode.left:=nil;
             elemnode.left:=nil;
             inc(paracount);
             inc(paracount);

+ 48 - 0
tests/test/tarrconstr16.pp

@@ -0,0 +1,48 @@
+program tarrconstr16;
+
+type
+  TEnum = (
+    teOne,
+    teTwo,
+    teThree
+  );
+
+  TTest1 = array[0..2] of LongInt;
+  TTest2 = array[1..3] of LongInt;
+  TTest3 = array[TEnum] of LongInt;
+  TTest4 = array[-1..1] of LongInt;
+
+procedure CheckArray(Actual, Expected: array of LongInt; Code: LongInt);
+var
+  i: SizeInt;
+begin
+  if Length(Actual) <> Length(Expected) then
+    Halt(Code);
+  for i := 0 to High(Actual) do
+    if Actual[i] <> Expected[i] then
+      Halt(Code);
+end;
+
+var
+  arr1: TTest1;
+  arr2: TTest2;
+  arr3: TTest3;
+  arr4: TTest4;
+begin
+  FillChar(arr1, SizeOf(arr1), 0);
+  FillChar(arr2, SizeOf(arr2), 0);
+  FillChar(arr3, SizeOf(arr3), 0);
+  FillChar(arr4, SizeOf(arr4), 0);
+
+  arr1 := [1, 2, 3];
+  CheckArray(arr1, [1, 2, 3], 1);
+
+  arr2 := [1, 2, 3];
+  CheckArray(arr2, [1, 2, 3], 2);
+
+  arr3 := [1, 2, 3];
+  CheckArray(arr3, [1, 2, 3], 3);
+
+  arr4 := [1, 2, 3];
+  CheckArray(arr4, [1, 2, 3], 4);
+end.