Przeglądaj źródła

* only ordinals and enums can be bitpacked -> don't give an error when
e.g. passing a 3-byte record in a bitpacked array as var-parameter
(mantis #17862)

git-svn-id: trunk@16317 -

Jonas Maebe 14 lat temu
rodzic
commit
d45ba6c966
3 zmienionych plików z 33 dodań i 0 usunięć
  1. 1 0
      .gitattributes
  2. 6 0
      compiler/nutils.pas
  3. 26 0
      tests/webtbs/tw17862.pp

+ 1 - 0
.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

+ 6 - 0
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

+ 26 - 0
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.
+