Pārlūkot izejas kodu

* Inherit recordalignment by objects. Otherwise static instances of child objects are not aligned properly. Mantis #10454.
+ Test.

git-svn-id: trunk@9495 -

yury 17 gadi atpakaļ
vecāks
revīzija
6a4ee90cb0
2 mainītis faili ar 24 papildinājumiem un 0 dzēšanām
  1. 2 0
      compiler/symdef.pas
  2. 22 0
      tests/webtbs/tw10454.pp

+ 2 - 0
compiler/symdef.pas

@@ -3907,6 +3907,8 @@ implementation
                   tObjectSymtable(symtable).datasize:=
                     tObjectSymtable(symtable).datasize+
                     tObjectSymtable(c.symtable).datasize;
+                  { inherit recordalignment }
+                  tObjectSymtable(symtable).recordalignment:=tObjectSymtable(c.symtable).recordalignment;
                   if (oo_has_vmt in objectoptions) and
                      (oo_has_vmt in c.objectoptions) then
                     tObjectSymtable(symtable).datasize:=

+ 22 - 0
tests/webtbs/tw10454.pp

@@ -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.