Browse Source

* second part of #40041 fixed
+ tests

florian 2 years ago
parent
commit
30e0df384d
4 changed files with 47 additions and 7 deletions
  1. 1 1
      compiler/nadd.pas
  2. 22 6
      tests/webtbs/tw39785.pp
  3. 24 0
      tests/webtbs/tw40041b.pp
  4. 0 0
      tw40041a.pp

+ 1 - 1
compiler/nadd.pas

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

+ 22 - 6
tests/webtbs/tw39785.pp

@@ -4,38 +4,54 @@ label A0, A1, B0, B1, C0, C1, D0, D1;
 
 var
 	x, y: single;
-	dontDrop: string;
     size: ptrint;
 
 begin
-	x := random;
+	x := random(0);
 A0:
 	y := x + 1 + 2 + 3 + 4 + 5 + 6; // folds
 A1:
-	writestr(dontDrop, y);
     size:=CodePointer(@A1) - CodePointer(@A0);
 	writeln('x + 1 + 2 + 3 + 4 + 5 + 6 = ', y, ' ', CodePointer(@A1) - CodePointer(@A0), ' b');
+	if y <> 21 then
+	begin
+		writeln('Expected 21!');
+		halt(1);
+	end;
 
 B0:
 	y := x + 1 - 2 + 3 - 4 + 5 - 6; // doesn’t fold
 B1:
-	writestr(dontDrop, y);
     if CodePointer(@B1) - CodePointer(@B0) > size then
       halt(1);
 	writeln('x + 1 - 2 + 3 - 4 + 5 - 6 = ', y, ' ', CodePointer(@B1) - CodePointer(@B0), ' b');
+	if y <> -3 then
+	begin
+		writeln('Expected -3!');
+		halt(2);
+	end;
 
 C0:
 	y := x - 1 - 2 - 3 - 4 - 5 - 6; // didn't fold at the time of making the issue, now folds
 C1:
-	writestr(dontDrop, y);
     if CodePointer(@C1) - CodePointer(@C0) > size then
       halt(1);
 	writeln('x - 1 - 2 - 3 - 4 - 5 - 6 = ', y, ' ', CodePointer(@C1) - CodePointer(@C0), ' b');
+	if y <> -21 then
+	begin
+		writeln('Expected -21!');
+		halt(3);
+	end;
+
 D0:
 	y := x - 1 + 2 - 3 + 4 - 5 + 6; // didn't fold at the time of making the issue, now folds
 D1:
-	writestr(dontDrop, y);
     if CodePointer(@D1) - CodePointer(@D0) > size then
       halt(1);
 	writeln('x - 1 + 2 - 3 + 4 - 5 + 6 = ', y, ' ', CodePointer(@D1) - CodePointer(@D0), ' b');
+	if y <> 3 then
+	begin
+		writeln('Expected 3!');
+		halt(4);
+	end;
 end.

+ 24 - 0
tests/webtbs/tw40041b.pp

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

+ 0 - 0
tests/webtbs/tw40041.pp → tw40041a.pp