Regression? Problem passing a packed record to a overriden, virtual, abstract method in fpc 2.7.1.

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Regression? Problem passing a packed record to a overriden, virtual, abstract method in fpc 2.7.1.

Reimar Grabowski
Hi,

see the following little program:

program argumentbug;

{$MODE ObjFpc}

uses classes;

type

TVector3 = packed record
  X, Y, Z: Single;
end;

TClassA = class
protected
  fVector: TVector3;
public
  procedure SetVector(AVector: TVector3); virtual; abstract;
end;

{ TClassB }

TClassB = class(TClassA)
public
  procedure SetVector(AVector: TVector3); override;
end;

{ TClassB }

procedure TClassB.SetVector(AVector: TVector3);
begin
  writeln('TClassB: ',AVector.X,',',AVector.Y,',',AVector.Z);
  fVector:=AVector;
end;

var
  MyVector: TVector3;
  MyClassB: TClassB;
begin
  MyVector.X:=0;
  MyVector.Y:=0;
  MyVector.Z:=3;
  MyClassB:=TClassB.Create;
  MyClassB.SetVector(MyVector);
end.

Obviously the expected output is 0,0,3 but in fact the output is 0,3,3.
I am sure that this used to work as my real code showing the problem is many years old.
(The problem stays even if I don't declare the method in TClassA abstract.)

OS: Ubuntu 12.10 64-Bit
Compiler: FPC 2.7.1 Rev. 23655

R.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Regression? Problem passing a packed record to a overriden, virtual, abstract method in fpc 2.7.1.

Mattias Gaertner
On Sun, 24 Feb 2013 23:20:23 +0100
Reimar Grabowski <[hidden email]> wrote:

> Hi,
>
> see the following little program:
>
> program argumentbug;
>
> {$MODE ObjFpc}
>
> uses classes;
>
> type
>
> TVector3 = packed record
>   X, Y, Z: Single;
> end;
>
> TClassA = class
> protected
>   fVector: TVector3;
> public
>   procedure SetVector(AVector: TVector3); virtual; abstract;
> end;
>
> { TClassB }
>
> TClassB = class(TClassA)
> public
>   procedure SetVector(AVector: TVector3); override;
> end;
>
> { TClassB }
>
> procedure TClassB.SetVector(AVector: TVector3);
> begin
>   writeln('TClassB: ',AVector.X,',',AVector.Y,',',AVector.Z);
>   fVector:=AVector;
> end;
>
> var
>   MyVector: TVector3;
>   MyClassB: TClassB;
> begin
>   MyVector.X:=0;
>   MyVector.Y:=0;
>   MyVector.Z:=3;
>   MyClassB:=TClassB.Create;
>   MyClassB.SetVector(MyVector);
> end.
>
> Obviously the expected output is 0,0,3 but in fact the output is 0,3,3.
> I am sure that this used to work as my real code showing the problem is many years old.
> (The problem stays even if I don't declare the method in TClassA abstract.)
>
> OS: Ubuntu 12.10 64-Bit
> Compiler: FPC 2.7.1 Rev. 23655

It works under 2.6.0 and 2.6.2 (Ubuntu 64bit).

Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Regression? Problem passing a packed record to a overriden, virtual, abstract method in fpc 2.7.1.

Mattias Gaertner
On Mon, 25 Feb 2013 22:54:51 +0100
Mattias Gaertner <[hidden email]> wrote:

> On Sun, 24 Feb 2013 23:20:23 +0100
> Reimar Grabowski <[hidden email]> wrote:
>
> > Hi,
> >
> > see the following little program:
> >
> > program argumentbug;
> >
> > {$MODE ObjFpc}
> >
> > uses classes;
> >
> > type
> >
> > TVector3 = packed record
> >   X, Y, Z: Single;
> > end;
> >
> > TClassA = class
> > protected
> >   fVector: TVector3;
> > public
> >   procedure SetVector(AVector: TVector3); virtual; abstract;
> > end;
> >
> > { TClassB }
> >
> > TClassB = class(TClassA)
> > public
> >   procedure SetVector(AVector: TVector3); override;
> > end;
> >
> > { TClassB }
> >
> > procedure TClassB.SetVector(AVector: TVector3);
> > begin
> >   writeln('TClassB: ',AVector.X,',',AVector.Y,',',AVector.Z);
> >   fVector:=AVector;
> > end;
> >
> > var
> >   MyVector: TVector3;
> >   MyClassB: TClassB;
> > begin
> >   MyVector.X:=0;
> >   MyVector.Y:=0;
> >   MyVector.Z:=3;
> >   MyClassB:=TClassB.Create;
> >   MyClassB.SetVector(MyVector);
> > end.
> >
> > Obviously the expected output is 0,0,3 but in fact the output is 0,3,3.
> > I am sure that this used to work as my real code showing the problem is many years old.
> > (The problem stays even if I don't declare the method in TClassA abstract.)
> >
> > OS: Ubuntu 12.10 64-Bit
> > Compiler: FPC 2.7.1 Rev. 23655
>
> It works under 2.6.0 and 2.6.2 (Ubuntu 64bit).

And it works under 2.7.1 rev 23661:
TClassB:  0.000000000E+00, 0.000000000E+00, 3.000000000E+00

Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Regression? Problem passing a packed record to a overriden, virtual, abstract method in fpc 2.7.1.

Reimar Grabowski
On Mon, 25 Feb 2013 22:59:26 +0100
Mattias Gaertner <[hidden email]> wrote:

> And it works under 2.7.1 rev 23661:
> TClassB:  0.000000000E+00, 0.000000000E+00, 3.000000000E+00
Thanks for the info. Updating now.

R.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Regression? Problem passing a packed record to a overriden, virtual, abstract method in fpc 2.7.1.

Reimar Grabowski
> On Mon, 25 Feb 2013 22:59:26 +0100
> Mattias Gaertner <[hidden email]> wrote:
>
> > And it works under 2.7.1 rev 23661:

Even with 23662 it does not work for me compiling from Lazarus. But from command line it works. So it is not a FPC problem.

Sorry for the noise.
Investigating further.
R.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Regression? Problem passing a packed record to a overriden, virtual, abstract method in fpc 2.7.1.

Reimar Grabowski
On Tue, 26 Feb 2013 00:02:33 +0100
Reimar Grabowski <[hidden email]> wrote:

> But from command line it works. So it is not a FPC problem.
I am really sorry for communicating with myself but I have spoken too early. Now I can reproduce the problem using just FPC, no Lazarus involved.
It gets triggered when compiling with range checking (-Cr) or with veryfying object method call validity (-CR).
At least now I know where the problem is and can workaround it by disabling both.
2.6.2 works correctly.

R.




_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Regression? Problem passing a packed record to a overriden, virtual, abstract method in fpc 2.7.1.

etrusco
On Mon, Feb 25, 2013 at 11:45 PM, Reimar Grabowski <[hidden email]> wrote:

> On Tue, 26 Feb 2013 00:02:33 +0100
> Reimar Grabowski <[hidden email]> wrote:
>
>> But from command line it works. So it is not a FPC problem.
> I am really sorry for communicating with myself but I have spoken too early. Now I can reproduce the problem using just FPC, no Lazarus involved.
> It gets triggered when compiling with range checking (-Cr) or with veryfying object method call validity (-CR).
> At least now I know where the problem is and can workaround it by disabling both.
> 2.6.2 works correctly.
>
> R.

FWIW even with these settings I can't reproduce the bug. Not even
enabling -O3 -Ou.
(FPC 2.6 on Win32, compiling from Lazarus)

-Flávio
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Regression? Problem passing a packed record to a overriden, virtual, abstract method in fpc 2.7.1.

Mattias Gaertner
In reply to this post by Reimar Grabowski
On Tue, 26 Feb 2013 03:45:37 +0100
Reimar Grabowski <[hidden email]> wrote:

> On Tue, 26 Feb 2013 00:02:33 +0100
> Reimar Grabowski <[hidden email]> wrote:
>
> > But from command line it works. So it is not a FPC problem.
> I am really sorry for communicating with myself but I have spoken too early. Now I can reproduce the problem using just FPC, no Lazarus involved.
> It gets triggered when compiling with range checking (-Cr) or with veryfying object method call validity (-CR).

Please submit a bug report.

> At least now I know where the problem is and can workaround it by disabling both.
> 2.6.2 works correctly.


Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Regression? Problem passing a packed record to a overriden, virtual, abstract method in fpc 2.7.1.

Reimar Grabowski
On Tue, 26 Feb 2013 08:58:58 +0100
Mattias Gaertner <[hidden email]> wrote:

> Please submit a bug report.
Done.

http://mantis.freepascal.org/view.php?id=23962

R.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal