fpc/tests/webtbs/tw39785.pp
2022-12-22 22:41:39 +01:00

58 lines
1.3 KiB
ObjectPascal
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{ %OPT=-O4 -Sg }
{$mode objfpc} {$h+}
label A0, A1, B0, B1, C0, C1, D0, D1;
var
x, y: single;
size: ptrint;
begin
x := random(0);
A0:
y := x + 1 + 2 + 3 + 4 + 5 + 6; // folds
A1:
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; // doesnt fold
B1:
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:
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:
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.