nielsAD / lape

Scripting engine with Pascal-like syntax for FPC and Delphi
112 stars 26 forks source link

Record comparison bug #160

Closed ollydev closed 2 years ago

ollydev commented 3 years ago

Issue happens on Win32 and Linux64. Needs to be investigated and check it doesn't happen elsewhere.

type TVec3 = packed record X,Y,Z: Byte; end; // Force CompareMem usage (Size <> 4,8,16,32) on record op_Equal

function Buggy: Boolean;
var
  Test: record A, B: TVec3; end;
begin
  Result := False or (Test.A <> Test.B);

  WriteLn('Bug: ', Result);              // True ??
  WriteLn(False or (Test.A <> Test.B));  // False - Correct
end;

begin
  Buggy();
end.
$000003F0 :: Eval lpeLongBool_NOT Stack[StackPos - 4] Stack[StackPos - 4] nil
$000003F0 :: IncStackPos 4
<niels> That line basically says Stack[StackPos - 4] := NOT Stack[StackPos - 4]
<niels> The IncStackPos after that shouldn't be there
<niels> Because we overwrite the old value on the stack, not push another value on it