Преглед на файлове

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

florian преди 2 години
родител
ревизия
e0fef23d77
променени са 2 файла, в които са добавени 14 реда и са изтрити 1 реда
  1. 1 1
      compiler/nadd.pas
  2. 13 0
      tests/webtbs/tw40041.pp

+ 1 - 1
compiler/nadd.pas

@@ -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 - 0
tests/webtbs/tw40041.pp

@@ -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.