소스 검색

* fixed packed arrays of enums in case of packenum 2/4

git-svn-id: trunk@4674 -
Jonas Maebe 19 년 전
부모
커밋
cc6a91a9bc
3개의 변경된 파일37개의 추가작업 그리고 5개의 파일을 삭제
  1. 1 0
      .gitattributes
  2. 13 5
      compiler/ncgmem.pas
  3. 23 0
      tests/test/tparray12.pp

+ 1 - 0
.gitattributes

@@ -6177,6 +6177,7 @@ tests/test/tpara2.pp svneol=native#text/plain
 tests/test/tparray1.pp svneol=native#text/plain
 tests/test/tparray10.pp svneol=native#text/plain
 tests/test/tparray11.pp svneol=native#text/plain
+tests/test/tparray12.pp svneol=native#text/plain
 tests/test/tparray2.pp svneol=native#text/plain
 tests/test/tparray3.pp svneol=native#text/plain
 tests/test/tparray4.pp svneol=native#text/plain

+ 13 - 5
compiler/ncgmem.pas

@@ -165,6 +165,8 @@ implementation
 *****************************************************************************}
 
     procedure tcgaddrnode.pass_2;
+      var
+        tmpref: treference;
       begin
          secondpass(left);
 
@@ -477,7 +479,8 @@ implementation
          byteoffs, bitoffs, alignpower: aint;
          temp : longint;
        begin
-         if (l mod 8) = 0 then
+         if ((l mod 8) = 0) and
+            ispowerof2(l div 8,temp) then
            begin
              update_reference_reg_mul(reg,l div 8);
              exit;
@@ -692,7 +695,8 @@ implementation
          if (left.resulttype.def.deftype=arraydef) and
             not(is_dynamic_array(left.resulttype.def)) and
             (not(is_packed_array(left.resulttype.def)) or
-             (mulsize mod 8 = 0)) then
+             ((mulsize mod 8 = 0) and
+              ispowerof2(mulsize div 8,temp))) then
            dec(location.reference.offset,bytemulsize*tarraydef(left.resulttype.def).lowrange);
 
          if right.nodetype=ordconstn then
@@ -763,9 +767,13 @@ implementation
                    end;
               end;
               if not(is_packed_array(left.resulttype.def)) or
-                 (mulsize mod 8 = 0) then
-                inc(location.reference.offset,
-                  bytemulsize*tordconstnode(right).value)
+                 ((mulsize mod 8 = 0) and
+                  ispowerof2(mulsize div 8,temp)) then
+                begin
+                  inc(location.reference.offset,
+                    bytemulsize*tordconstnode(right).value);
+                  newsize:=int_cgsize(bytemulsize);
+                end
               else
                 begin
                   subsetref.ref := location.reference;

+ 23 - 0
tests/test/tparray12.pp

@@ -0,0 +1,23 @@
+{$packenum 2}
+type
+  tenum = (ea,eb,ec,ed,ee,ef:=255);
+  tb = array[1..16] of byte;
+const
+  res: array[1..6] of byte = (0,1,2,3,4,255);
+var
+  a: bitpacked array[1..16] of tenum;
+  i: longint;
+begin
+  writeln(sizeof(a));
+  a[1]:=ea;
+  a[2]:=eb;
+  a[3]:=ec;
+  a[6]:=ef;
+  a[5]:=ee;
+  a[4]:=ed;
+  for i := 1 to 6 do
+    begin writeln(tb(a)[i]);
+    if (tb(a)[i] <> res[i]) then
+      halt(1); end;
+end.
+