View Issue Details

IDProjectCategoryView StatusLast Update
0037301FPCCompilerpublic2020-07-07 22:22
ReporterJesus Reyes Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0037301: -O1 optimization problem
DescriptionThere 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 Reproduceprogram 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 InformationTested under windows 10
FPC 3.0.4 and 3.2.0 seems to be not affected by this problem.
TagsNo tags attached.
Fixed in Revision45732
FPCOldBugId
FPCTarget-
Attached Files

Activities

Florian

2020-07-05 11:19

administrator   ~0123761

It was only a problem on i386.

Marco van de Voort

2020-07-05 13:47

manager   ~0123762

(Playing with png filters? :-)

Bi0T1N

2020-07-05 15:58

reporter   ~0123763

Shouldn't the test (https://github.com/graemeg/freepascal/commit/15567a8a14f1059cac904ced4b85945ae81cfe1c) contain


if w <> 53 then halt;


to fail if the value doesn't match?

Jesus Reyes

2020-07-07 00:45

developer   ~0123792

thanks.

Florian

2020-07-07 22:22

administrator   ~0123805

@Bi0T1N: Thanks, fixed.

Issue History

Date Modified Username Field Change
2020-07-05 09:31 Jesus Reyes New Issue
2020-07-05 11:19 Florian Assigned To => Florian
2020-07-05 11:19 Florian Status new => resolved
2020-07-05 11:19 Florian Resolution open => fixed
2020-07-05 11:19 Florian Fixed in Version => 3.3.1
2020-07-05 11:19 Florian Fixed in Revision => 45732
2020-07-05 11:19 Florian FPCTarget => -
2020-07-05 11:19 Florian Note Added: 0123761
2020-07-05 13:47 Marco van de Voort Note Added: 0123762
2020-07-05 15:58 Bi0T1N Note Added: 0123763
2020-07-07 00:45 Jesus Reyes Status resolved => closed
2020-07-07 00:45 Jesus Reyes Note Added: 0123792
2020-07-07 22:22 Florian Note Added: 0123805