diff --git a/.gitattributes b/.gitattributes index 02a9356470..a6f6840991 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10735,6 +10735,7 @@ tests/webtbs/tw17715.pp svneol=native#text/plain tests/webtbs/tw1779.pp svneol=native#text/plain tests/webtbs/tw1780.pp svneol=native#text/plain tests/webtbs/tw17836.pp svneol=native#text/plain +tests/webtbs/tw17862.pp svneol=native#text/plain tests/webtbs/tw1792.pp svneol=native#text/plain tests/webtbs/tw1792a.pp svneol=native#text/plain tests/webtbs/tw1798.pp svneol=native#text/plain diff --git a/compiler/nutils.pas b/compiler/nutils.pas index 767d5706c9..0b7e728cb6 100644 --- a/compiler/nutils.pas +++ b/compiler/nutils.pas @@ -1151,10 +1151,16 @@ implementation vecn: result:= is_packed_array(tvecnode(n).left.resultdef) and + { only orddefs and enumdefs are actually bitpacked. Don't consider + e.g. an access to a 3-byte record as "bitpacked", since it + isn't } + (tvecnode(n).left.resultdef.typ in [orddef,enumdef]) and not(tarraydef(tvecnode(n).left.resultdef).elepackedbitsize in [8,16,32,64]); subscriptn: result:= is_packed_record_or_object(tsubscriptnode(n).left.resultdef) and + { see above } + (tsubscriptnode(n).vs.vardef.typ in [orddef,enumdef]) and (not(tsubscriptnode(n).vs.vardef.packedbitsize in [8,16,32,64]) or (tsubscriptnode(n).vs.fieldoffset mod 8 <> 0)); else diff --git a/tests/webtbs/tw17862.pp b/tests/webtbs/tw17862.pp new file mode 100644 index 0000000000..bd0cfa7d4b --- /dev/null +++ b/tests/webtbs/tw17862.pp @@ -0,0 +1,26 @@ +{$mode objfpc} +type + TField = record + a,b,c: byte; + end; + tarray = bitpacked array[0..3] of tfield; + +procedure test(var a: tfield); +begin + if a.a<>3 then + halt(1); + if a.b<>4 then + halt(2); + if a.c<>5 then + halt(3); +end; + +var + a: tarray; +begin + a[1].a:=3; + a[1].b:=4; + a[1].c:=5; + test(a[1]); +end. +