-O1 optimization problem
Original Reporter info from Mantis: Jesus @jramx
-
Reporter name: Jesus Reyes
Original Reporter info from Mantis: Jesus @jramx
- Reporter name: Jesus Reyes
Description:
There is a problem when optimization is set to -O1 and the abs intrinsic is used in combination with several ordinal types, see the program in Steps to Reproduce.
This problem affects reading of png files where the result is corrupted images, this is when using the fpreadpng.pp unit.
The affected portion of code is this:
....
var dl, dp, dlp : word; // index for previous and distances for:
l, p, lp : byte; // r:predictor, Left, Previous, LeftPrevious
r : integer;
begin
l := PrevSample(index);
lp := PrevLinePrevSample(index);
p := PreviousLine(index);
r := l + p - lp;
dl := abs (r - l);
dlp := abs (r - lp);
dp := abs (r - p);
....
Steps to reproduce:
program testbug;
{$mode objfpc}{$h+}
var
i: Integer;
b: Byte;
w: Word;
begin
i := 53;
b := 0;
w := abs(i-b);
WriteLn(w);
end.
// The result should be 53, but it actually prints 0
Additional information:
Tested under windows 10
FPC 3.0.4 and 3.2.0 seems to be not affected by this problem.
Mantis conversion info:
- Mantis ID: 37301
- Build: 45731
- Version: 3.3.1
- Fixed in version: 3.3.1
- Fixed in revision: 45732 (#3caacc52)