Browse Source

* type conversions of constants require that unneeded bits are cut off

git-svn-id: trunk@34797 -
florian 8 years ago
parent
commit
4862e64b53
1 changed files with 20 additions and 0 deletions
  1. 20 0
      compiler/ncnv.pas

+ 20 - 0
compiler/ncnv.pas

@@ -2791,6 +2791,26 @@ implementation
                        { swap value back, but according to new type }
                        if (target_info.endian = endian_big) and (nf_absolute in flags) then
                          swap_const_value(tordconstnode(left).value,resultdef.size);
+
+                       { cut off the new value? }
+                       if resultdef.size<left.resultdef.size then
+                         case resultdef.size of
+                           1:
+                             if is_signed(resultdef) then
+                               tordconstnode(left).value:=tordconstnode(left).value and shortint($ff)
+                             else
+                               tordconstnode(left).value:=tordconstnode(left).value and byte($ff);
+                           2:
+                             if is_signed(resultdef) then
+                               tordconstnode(left).value:=tordconstnode(left).value and smallint($ffff)
+                             else
+                               tordconstnode(left).value:=tordconstnode(left).value and word($ffff);
+                           4:
+                             if is_signed(resultdef) then
+                               tordconstnode(left).value:=tordconstnode(left).value and longint($ffffffff)
+                             else
+                               tordconstnode(left).value:=tordconstnode(left).value and dword($ffffffff);
+                         end;
                      end;
                    left.resultdef:=resultdef;
                    tordconstnode(left).typedef:=resultdef;