mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 13:29:19 +02:00
* Inherit recordalignment by objects. Otherwise static instances of child objects are not aligned properly. Mantis #10454.
+ Test. git-svn-id: trunk@9495 -
This commit is contained in:
parent
1361239124
commit
6a4ee90cb0
@ -3907,6 +3907,8 @@ implementation
|
|||||||
tObjectSymtable(symtable).datasize:=
|
tObjectSymtable(symtable).datasize:=
|
||||||
tObjectSymtable(symtable).datasize+
|
tObjectSymtable(symtable).datasize+
|
||||||
tObjectSymtable(c.symtable).datasize;
|
tObjectSymtable(c.symtable).datasize;
|
||||||
|
{ inherit recordalignment }
|
||||||
|
tObjectSymtable(symtable).recordalignment:=tObjectSymtable(c.symtable).recordalignment;
|
||||||
if (oo_has_vmt in objectoptions) and
|
if (oo_has_vmt in objectoptions) and
|
||||||
(oo_has_vmt in c.objectoptions) then
|
(oo_has_vmt in c.objectoptions) then
|
||||||
tObjectSymtable(symtable).datasize:=
|
tObjectSymtable(symtable).datasize:=
|
||||||
|
22
tests/webtbs/tw10454.pp
Normal file
22
tests/webtbs/tw10454.pp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{$mode objfpc}
|
||||||
|
|
||||||
|
type
|
||||||
|
TMyObject = object
|
||||||
|
Int: longint;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TMyObject2 = object(TMyObject)
|
||||||
|
end;
|
||||||
|
|
||||||
|
TMyClass = class
|
||||||
|
FByte: byte;
|
||||||
|
Obj: TMyObject2; // instance of this object is not aligned
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
myclass: TMyClass;
|
||||||
|
begin
|
||||||
|
myclass:=TMyClass.Create;
|
||||||
|
myclass.obj.int:=1; // Crash due to unaligned data access
|
||||||
|
myclass.Free;
|
||||||
|
end.
|
Loading…
Reference in New Issue
Block a user