فهرست منبع

* work around broken x86 shifting in bitpacked value calculation
(mantis #36156)

git-svn-id: trunk@43186 -

Jonas Maebe 5 سال پیش
والد
کامیت
51c6ebfe54
3فایلهای تغییر یافته به همراه36 افزوده شده و 5 حذف شده
  1. 1 0
      .gitattributes
  2. 18 5
      compiler/ngtcon.pas
  3. 17 0
      tests/webtbs/tw36156.pp

+ 1 - 0
.gitattributes

@@ -17840,6 +17840,7 @@ tests/webtbs/tw35965.pp svneol=native#text/pascal
 tests/webtbs/tw35982.pp svneol=native#text/pascal
 tests/webtbs/tw36013.pp svneol=native#text/pascal
 tests/webtbs/tw3612.pp svneol=native#text/plain
+tests/webtbs/tw36156.pp svneol=native#text/plain
 tests/webtbs/tw3617.pp svneol=native#text/plain
 tests/webtbs/tw3619.pp svneol=native#text/plain
 tests/webtbs/tw3621.pp svneol=native#text/plain

+ 18 - 5
compiler/ngtcon.pas

@@ -342,20 +342,33 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
         if (target_info.endian=endian_big) then
           begin
             { bitpacked format: left-aligned (i.e., "big endian bitness") }
-            bp.curval:=bp.curval or ((value shl (AIntBits-bp.packedbitsize)) shr bp.curbitoffset);
+            { work around broken x86 shifting }
+            if (AIntBits<>bp.packedbitsize) and
+               (bp.curbitoffset<AIntBits) then
+              bp.curval:=bp.curval or ((value shl (AIntBits-bp.packedbitsize)) shr bp.curbitoffset);
             shiftcount:=((AIntBits-bp.packedbitsize)-bp.curbitoffset);
             { carry-over to the next element? }
             if (shiftcount<0) then
-              bp.nextval:=(value and ((aword(1) shl (-shiftcount))-1)) shl
-                          (AIntBits+shiftcount)
+              begin
+                if shiftcount>=AIntBits then
+                  bp.nextval:=(value and ((aword(1) shl (-shiftcount))-1)) shl
+                              (AIntBits+shiftcount)
+                else
+                  bp.nextval:=0
+              end
           end
         else
           begin
             { bitpacked format: right aligned (i.e., "little endian bitness") }
-            bp.curval:=bp.curval or (value shl bp.curbitoffset);
+            { work around broken x86 shifting }
+            if bp.curbitoffset<AIntBits then
+              bp.curval:=bp.curval or (value shl bp.curbitoffset);
             { carry-over to the next element? }
             if (bp.curbitoffset+bp.packedbitsize>AIntBits) then
-              bp.nextval:=value shr (AIntBits-bp.curbitoffset)
+              if bp.curbitoffset>0 then
+                bp.nextval:=value shr (AIntBits-bp.curbitoffset)
+              else
+                bp.nextval:=0;
           end;
         inc(bp.curbitoffset,bp.packedbitsize);
       end;

+ 17 - 0
tests/webtbs/tw36156.pp

@@ -0,0 +1,17 @@
+program Project1;
+type
+  TBitSize = -7..7;
+  TFpDbgValueSize = bitpacked record
+    Size: Int64;
+    BitSize: TBitSize;
+  end;
+
+const
+  gcFpDbgValueSize: TFpDbgValueSize = (Size: $7FFFFFFF; BitSize: 2);
+
+begin
+  writeln(hexstr(gcFpDbgValueSize.Size,16));
+  writeln(gcFpDbgValueSize.BitSize);
+  if gcFpDbgValueSize.Size<>$7fffffff then
+    halt(1);
+end.