Browse Source

* New test to evaluate i39918

J. Gareth "Curious Kit" Moreton 2 years ago
parent
commit
fa76baa3d4
1 changed files with 46 additions and 0 deletions
  1. 46 0
      tests/webtbs/tw39918.pp

+ 46 - 0
tests/webtbs/tw39918.pp

@@ -0,0 +1,46 @@
+{ %OPT=-O3 }
+
+{ Test triggers incorrect AddMov2Mov optimisation
+  (second register not checked for modification) }
+program tw39918;
+
+type
+
+  ObjectA = object
+    Index: Cardinal;
+  end;
+
+  ObjectB = object
+    ObjectAArray: array of ObjectA;
+    TestString: String; //Needed for crash
+  end;
+
+  ObjectC = object
+    TestValue: Uint32;
+  end;
+
+var
+
+  ObjectBArray: array of ObjectB;
+  ObjectCArray: array of ObjectC;
+  BIndex: Integer = 0;
+
+begin
+  //Init variables
+  setlength(ObjectBArray, 1);
+  setlength(ObjectBArray[0].ObjectAArray, 1);
+  SetLength(ObjectCArray, 1);
+  ObjectCArray[0].TestValue := 0;
+  ObjectBArray[0].ObjectAArray[0].Index := 0;
+  ObjectBArray[0].TestString := 'Needed';
+
+  //Works
+  writeln(ObjectCArray[ObjectBArray[BIndex].ObjectAArray[0].Index].TestValue);
+
+  //Crash
+  with ObjectBArray[BIndex], ObjectCArray[ObjectAArray[0].Index] do
+  begin
+    writeln(TestValue);
+  end;
+  WriteLn('ok');
+end.