Bug#895693: arm64: Incorrect record member value when returned from a function

2018-04-14 Thread Paul Gevers
Hi Punit,

On 14-04-18 20:30, Punit Agrawal wrote:
> While investigating build failure reported in #891682 I've stumbled
> upon what seems like a free pascal compiler issue on arm64.

Please let us know when you filed the bug upstream and set the forwarded
field of this bug appropriately. Such that we can port back the solution
when upstream fixes the issue.

Mind you, upstream hasn't released arm64 support yet (that is a Debian
thing), so be gentle with them.

Paul



signature.asc
Description: OpenPGP digital signature


Bug#895693: arm64: Incorrect record member value when returned from a function

2018-04-14 Thread Punit Agrawal
Source: fpc
Version: 3.0.4+dfsg-16
Severity: normal

Dear Maintainer,

While investigating build failure reported in #891682 I've stumbled
upon what seems like a free pascal compiler issue on arm64.

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.

Thanks,
Punit
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.