diff --git a/compiler/nmem.pas b/compiler/nmem.pas index 089cba0aae..668433ccb5 100644 --- a/compiler/nmem.pas +++ b/compiler/nmem.pas @@ -587,9 +587,18 @@ implementation begin offset:=tabsolutevarsym(tloadnode(hp).symtableentry).addroffset; hp:=left; - while assigned(hp) and (hp.nodetype=subscriptn) do + while assigned(hp)and(hp.nodetype=subscriptn) do begin - inc(offset,tsubscriptnode(hp).vs.fieldoffset); + hsym:=tsubscriptnode(hp).vs; + if tabstractrecordsymtable(hsym.owner).is_packed then + begin + { can't calculate the address of a non-byte aligned field } + if (hsym.fieldoffset mod 8)<>0 then + exit; + inc(offset,hsym.fieldoffset div 8) + end + else + inc(offset,hsym.fieldoffset); hp:=tunarynode(hp).left; end; if nf_typedaddr in flags then diff --git a/tests/webtbs/tw19357.pp b/tests/webtbs/tw19357.pp index f795bb6718..05fbe6a4f2 100644 --- a/tests/webtbs/tw19357.pp +++ b/tests/webtbs/tw19357.pp @@ -1,6 +1,6 @@ program tw19357; type - TLvl0 = packed record + TLvl0 = bitpacked record a,b: longword; end;