Browse Source

Merged revisions 7847 via svnmerge from
svn+ssh://[email protected]/FPC/svn/fpc/trunk

........
r7847 | jonas | 2007-06-29 17:34:11 +0200 (Fri, 29 Jun 2007) | 3 lines

* fixed calculation of offset of constant indexing of bitpacked arrays of
non-ordinal types (mantis #9174)

........

git-svn-id: branches/fixes_2_2@7865 -

Jonas Maebe 18 years ago
parent
commit
60b30934da
3 changed files with 60 additions and 1 deletions
  1. 1 0
      .gitattributes
  2. 3 1
      compiler/ncgmem.pas
  3. 56 0
      tests/webtbs/tw9174.pp

+ 1 - 0
.gitattributes

@@ -8147,6 +8147,7 @@ tests/webtbs/tw9076a.pp svneol=native#text/plain
 tests/webtbs/tw9085.pp svneol=native#text/plain
 tests/webtbs/tw9098.pp svneol=native#text/plain
 tests/webtbs/tw9107.pp svneol=native#text/plain
+tests/webtbs/tw9174.pp svneol=native#text/plain
 tests/webtbs/tw9179.pp svneol=native#text/plain
 tests/webtbs/ub1873.pp svneol=native#text/plain
 tests/webtbs/ub1883.pp svneol=native#text/plain

+ 3 - 1
compiler/ncgmem.pas

@@ -709,7 +709,9 @@ implementation
             not(is_dynamic_array(left.resultdef)) and
             (not(is_packed_array(left.resultdef)) or
              ((mulsize mod 8 = 0) and
-              ispowerof2(mulsize div 8,temp))) then
+              ispowerof2(mulsize div 8,temp)) or
+              { only orddefs are bitpacked }
+              not is_ordinal(resultdef)) then
            dec(location.reference.offset,bytemulsize*tarraydef(left.resultdef).lowrange);
 
          if right.nodetype=ordconstn then

+ 56 - 0
tests/webtbs/tw9174.pp

@@ -0,0 +1,56 @@
+{$mode macpas}
+
+program packed_offset_bug;
+
+type
+	SInt16 = integer;
+	Point = record
+		case SInt16 of
+		0: (
+			v: SInt16;
+			h: SInt16;
+		   );
+		1: (
+			vh: array [0..1] of SInt16;
+			);
+	end;
+	PointPtr = ^Point;
+	Rect = record
+		case SInt16 of
+		0: (
+			top: SInt16;
+			left: SInt16;
+			bottom: SInt16;
+			right: SInt16;
+		   );
+		1: (
+			topLeft: Point;
+			botRight: Point;
+		   );
+	end;
+	RectPtr = ^Rect;
+
+var
+	gMeasStrs: packed array[1..64] of string[4];
+	gMeasStrRects: array[1..64] of Rect;
+
+var
+  i,j,k: longint;
+begin
+	writeln( 'SizeOf gMeasStrs)        = ', SizeOf( gMeasStrs));
+	writeln( 'SizeOf gMeasStrRects)    = ', SizeOf( gMeasStrRects));
+	writeln( 'Offset gMeasStrs[  1   ] = ', ptruint( @gMeasStrs[      1]) -ptruint( @gMeasStrs));
+	writeln( 'Offset gMeasStrs[ 64, 4] = ', ptruint( @gMeasStrs[ 64,  4]) - ptruint( @gMeasStrs));
+	writeln( 'Offset gMeasStrRects     = ', ptruint( @gMeasStrRects)      - ptruint( @gMeasStrs));
+        i:=1;
+        j:=64;
+        k:=4;
+        if (SizeOf( gMeasStrs) <> 320) or
+           (SizeOf( gMeasStrRects) <> 512) or
+           (ptruint( @gMeasStrs[      1]) - ptruint( @gMeasStrs) <> 0) or
+           (ptruint( @gMeasStrs[ 64,  4])- ptruint( @gMeasStrs)<>319) or
+           (ptruint( @gMeasStrs[      i]) - ptruint( @gMeasStrs) <> 0) or
+           (ptruint( @gMeasStrs[ j,  k])- ptruint( @gMeasStrs)<>319) then
+          halt(1);
+end.
+