Browse Source

* keep signess of orginal variable in shl/shr operation

git-svn-id: trunk@8143 -
peter 18 years ago
parent
commit
8bd95f4dd4
3 changed files with 27 additions and 1 deletions
  1. 1 0
      .gitattributes
  2. 7 1
      compiler/nmat.pas
  3. 19 0
      tests/webtbs/tw9299.pp

+ 1 - 0
.gitattributes

@@ -8353,6 +8353,7 @@ tests/webtbs/tw9209.pp svneol=native#text/plain
 tests/webtbs/tw9221.pp svneol=native#text/plain
 tests/webtbs/tw9221.pp svneol=native#text/plain
 tests/webtbs/tw9261.pp svneol=native#text/x-pascal
 tests/webtbs/tw9261.pp svneol=native#text/x-pascal
 tests/webtbs/tw9278.pp svneol=native#text/plain
 tests/webtbs/tw9278.pp svneol=native#text/plain
+tests/webtbs/tw9299.pp -text
 tests/webtbs/tw9306a.pp -text
 tests/webtbs/tw9306a.pp -text
 tests/webtbs/tw9306b.pp -text
 tests/webtbs/tw9306b.pp -text
 tests/webtbs/tw9309.pp -text
 tests/webtbs/tw9309.pp -text

+ 7 - 1
compiler/nmat.pas

@@ -516,7 +516,13 @@ implementation
            the same as 'shl 1'. It's ugly but compatible with delphi/tp/gcc }
            the same as 'shl 1'. It's ugly but compatible with delphi/tp/gcc }
          if (not is_64bit(left.resultdef)) and
          if (not is_64bit(left.resultdef)) and
             (torddef(left.resultdef).ordtype<>u32bit) then
             (torddef(left.resultdef).ordtype<>u32bit) then
-           inserttypeconv(left,s32inttype);
+           begin
+             { keep singness of orignal type }
+             if is_signed(left.resultdef) then
+               inserttypeconv(left,s32inttype)
+             else
+               inserttypeconv(left,u32inttype);
+           end;
 
 
          inserttypeconv(right,sinttype);
          inserttypeconv(right,sinttype);
 
 

+ 19 - 0
tests/webtbs/tw9299.pp

@@ -0,0 +1,19 @@
+{$mode objfpc}
+{$R+}
+
+function GetShiftedCard(const c: Cardinal): Cardinal;
+begin
+  Result := c shl 24;
+end;
+
+function GetShiftedByte(const c: Byte): Cardinal;
+begin
+  Result := c shl 24;
+end;
+
+begin
+  WriteLn(GetShiftedCard(200));
+
+  WriteLn(GetShiftedByte(200));
+
+end.