* properly transform a+const1-const2 into a+const1+(-const2), resolves #40041

This commit is contained in:
florian 2022-12-21 22:34:46 +01:00
parent 48b9751419
commit e0fef23d77
2 changed files with 14 additions and 1 deletions

View File

@ -1483,7 +1483,7 @@ implementation
begin
Result:=getcopy;
Result.nodetype:=addn;
right:=cunaryminusnode.create(right);
taddnode(result).right:=cunaryminusnode.create(taddnode(result).right);
exit;
end;

13
tests/webtbs/tw40041.pp Normal file
View File

@ -0,0 +1,13 @@
{$mode objfpc}
function Shift(x: single): single; noinline;
begin
result := x + 10.0 - 1.0;
end;
begin
if Shift(5.0) <> 14.0 then
begin
writeln('Got ', Shift(5.0):0:1, ', expected 14.0.');
halt(1);
end;
end.