Browse Source

* return the next field from tabstractrecordsymtable.findfieldbyoffset() if
there is no field at that exact offset, so we can also use it to find the
next field in case there is alignment padding

git-svn-id: branches/hlcgllvm@28754 -

Jonas Maebe 11 years ago
parent
commit
9d9e0a578b
1 changed files with 8 additions and 1 deletions
  1. 8 1
      compiler/symtable.pas

+ 8 - 1
compiler/symtable.pas

@@ -102,6 +102,9 @@ interface
           procedure alignrecord(fieldoffset:asizeint;varalign:shortint);
           procedure alignrecord(fieldoffset:asizeint;varalign:shortint);
           procedure addfield(sym:tfieldvarsym;vis:tvisibility);
           procedure addfield(sym:tfieldvarsym;vis:tvisibility);
           procedure addfieldlist(list: tfpobjectlist; maybereorder: boolean);
           procedure addfieldlist(list: tfpobjectlist; maybereorder: boolean);
+          { returns the field closest to this offset (may not be exact because
+            of padding; internalerrors for variant records, assumes fields are
+            ordered by increasing offset) }
           function findfieldbyoffset(offset:asizeint): tfieldvarsym;
           function findfieldbyoffset(offset:asizeint): tfieldvarsym;
           procedure addalignmentpadding;
           procedure addalignmentpadding;
           procedure insertdef(def:TDefEntry);override;
           procedure insertdef(def:TDefEntry);override;
@@ -1244,11 +1247,15 @@ implementation
         i: longint;
         i: longint;
         sym: tsym;
         sym: tsym;
       begin
       begin
+        { there could be multiple fields in case of a variant record }
+        if (defowner.typ=recorddef) and
+           trecorddef(defowner).isunion then
+          internalerror(2014090403);
         for i:=0 to SymList.count-1 do
         for i:=0 to SymList.count-1 do
           begin
           begin
             sym:=tsym(symlist[i]);
             sym:=tsym(symlist[i]);
             if (sym.typ=fieldvarsym) and
             if (sym.typ=fieldvarsym) and
-               (tfieldvarsym(sym).fieldoffset=offset) then
+               (tfieldvarsym(sym).fieldoffset>=offset) then
               begin
               begin
                 result:=tfieldvarsym(sym);
                 result:=tfieldvarsym(sym);
                 exit;
                 exit;