View Issue Details

IDProjectCategoryView StatusLast Update
0033607FPCCompilerpublic2019-01-01 17:50
ReporterpunitAssigned ToJonas Maebe 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Platformarm64OSDebian LinuxOS Version
Product Version3.0.4Product Build 
Target Version3.2.0Fixed in Version3.2.0 
Summary0033607: arm64: Incorrect record member value when returned from a function
DescriptionWhile investigating build failure reported in debian bug[0] I've stumbled
upon what seems like a free pascal compiler issue on arm64.

[0] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=891682

The value of a member of a record returned by a function varies depending on usage.

The observed value of

   S.Width where S := R.ScaleAround0(2)

differs from the value of

   R.ScaleAround0(2).Width

The values differ on arm64 but agree on x86-64.

The attached reproducer gives the following output on arm64 -

    arm64:~/src/fpc-test$ ./test
    S.Width=0 R.ScaleAround0(2).Width=214748364800

while on x86-64

    x86-64$ ./test
    S.Width=0 R.ScaleAround0(2).Width=0
    
The reproducer is derived from a failing test in Castle Game Engine.
Steps To ReproduceRun the attached test.pas on arm64 and x86 machine.
TagsNo tags attached.
Fixed in Revision40512,40735
FPCOldBugId
FPCTarget
Attached Files
  • test.pas (931 bytes)
    program test;
    
    {$mode objfpc}{$H+}
    {$modeSwitch advancedRecords}
    
    type
       TRectangle = record
    		   public
    		   Left, Bottom: Integer;
    		   Width, Height: Cardinal;
    
    		function ScaleAround0(const Factor: Single): TRectangle;
    		end;
    
    function TRectangle.ScaleAround0(const Factor: Single): TRectangle;
    begin
       if Width <= 0 then
       begin
          Result.Width  := Width;
          Result.Left   := Left;
       end else
          Writeln('This should never happen');
    
       Result.Height := Height;
       Result.Bottom := Bottom;
    end;
    
    function Rectangle(const Left, Bottom: Integer;
    		   const Width, Height: Cardinal): TRectangle;
    begin
       Rectangle.Left := Left;
       Rectangle.Bottom := Bottom;
       Rectangle.Width := Width;
       Rectangle.Height := Height;
    end;
    
    var
       R, S	:  TRectangle;
    begin
       R := Rectangle(10, 20, 0, 50);
       S := R.ScaleAround0(2);
    
       Writeln('S.Width=', S.Width, ' R.ScaleAround0(2).Width=', R.ScaleAround0(2).Width);   
    end.
    
    test.pas (931 bytes)

Activities

punit

2018-04-14 20:49

reporter  

test.pas (931 bytes)
program test;

{$mode objfpc}{$H+}
{$modeSwitch advancedRecords}

type
   TRectangle = record
		   public
		   Left, Bottom: Integer;
		   Width, Height: Cardinal;

		function ScaleAround0(const Factor: Single): TRectangle;
		end;

function TRectangle.ScaleAround0(const Factor: Single): TRectangle;
begin
   if Width <= 0 then
   begin
      Result.Width  := Width;
      Result.Left   := Left;
   end else
      Writeln('This should never happen');

   Result.Height := Height;
   Result.Bottom := Bottom;
end;

function Rectangle(const Left, Bottom: Integer;
		   const Width, Height: Cardinal): TRectangle;
begin
   Rectangle.Left := Left;
   Rectangle.Bottom := Bottom;
   Rectangle.Width := Width;
   Rectangle.Height := Height;
end;

var
   R, S	:  TRectangle;
begin
   R := Rectangle(10, 20, 0, 50);
   S := R.ScaleAround0(2);

   Writeln('S.Width=', S.Width, ' R.ScaleAround0(2).Width=', R.ScaleAround0(2).Width);   
end.
test.pas (931 bytes)

Thaddy de Koning

2018-04-14 22:30

reporter   ~0107791

Last edited: 2018-04-14 22:35

View 5 revisions

I tested this for AARCH64 and when integer is changed to NativeInt it has the correct result.
Can it be that AARCH64 maintainer needs a look at the integer type? I see there are multiple exceptions about a 32 bit size. But NativeInt works.

Issue History

Date Modified Username Field Change
2018-04-14 20:49 punit New Issue
2018-04-14 20:49 punit File Added: test.pas
2018-04-14 22:30 Thaddy de Koning Note Added: 0107791
2018-04-14 22:30 Thaddy de Koning Note Edited: 0107791 View Revisions
2018-04-14 22:34 Thaddy de Koning Note Edited: 0107791 View Revisions
2018-04-14 22:34 Thaddy de Koning Note Edited: 0107791 View Revisions
2018-04-14 22:35 Thaddy de Koning Note Edited: 0107791 View Revisions
2018-12-09 15:47 Jonas Maebe Fixed in Revision => 40512
2018-12-09 15:47 Jonas Maebe Status new => resolved
2018-12-09 15:47 Jonas Maebe Fixed in Version => 3.3.1
2018-12-09 15:47 Jonas Maebe Resolution open => fixed
2018-12-09 15:47 Jonas Maebe Assigned To => Jonas Maebe
2018-12-09 15:47 Jonas Maebe Target Version => 3.2.0
2019-01-01 17:50 Jonas Maebe Fixed in Revision 40512 => 40512,40735
2019-01-01 17:50 Jonas Maebe Fixed in Version 3.3.1 => 3.2.0