diff --git a/.gitattributes b/.gitattributes index 0bea12d504..a4560fc316 100644 --- a/.gitattributes +++ b/.gitattributes @@ -13349,6 +13349,7 @@ tests/tbs/tb0672.pp svneol=native#text/pascal tests/tbs/tb0673.pp svneol=native#text/pascal tests/tbs/tb0674.pp svneol=native#text/pascal tests/tbs/tb0675.pp svneol=native#text/pascal +tests/tbs/tb0676.pp svneol=native#text/pascal tests/tbs/ub0060.pp svneol=native#text/plain tests/tbs/ub0069.pp svneol=native#text/plain tests/tbs/ub0119.pp svneol=native#text/plain diff --git a/rtl/arm/arm.inc b/rtl/arm/arm.inc index 1f009767c3..b5793f5f0c 100644 --- a/rtl/arm/arm.inc +++ b/rtl/arm/arm.inc @@ -1190,13 +1190,13 @@ function SwapEndian(const AValue: SmallInt): SmallInt;{$ifdef SYSTEMINLINE}inlin { is turned into "longint(AValue) shr 8", so if AValue < 0 then } { the sign bits from the upper 16 bits are shifted in rather than } { zeroes. } - Result := SmallInt((Word(AValue) shr 8) or (Word(AValue) shl 8)); + Result := ((Word(AValue) shr 8) or (Word(AValue) shl 8)) and $ffff; end; function SwapEndian(const AValue: Word): Word;{$ifdef SYSTEMINLINE}inline;{$endif} begin - Result := Word((AValue shr 8) or (AValue shl 8)); + Result := ((AValue shr 8) or (AValue shl 8)) and $ffff; end; (* diff --git a/rtl/inc/generic.inc b/rtl/inc/generic.inc index aa590e5c5e..b7750e2322 100644 --- a/rtl/inc/generic.inc +++ b/rtl/inc/generic.inc @@ -2663,13 +2663,13 @@ function SwapEndian(const AValue: SmallInt): SmallInt;{$ifdef SYSTEMINLINE}inlin { is turned into "longint(AValue) shr 8", so if AValue < 0 then } { the sign bits from the upper 16 bits are shifted in rather than } { zeroes. } - Result := SmallInt((Word(AValue) shr 8) or (Word(AValue) shl 8)); + Result := ((Word(AValue) shr 8) or (Word(AValue) shl 8)) and $ffff; end; {$ifndef cpujvm} function SwapEndian(const AValue: Word): Word;{$ifdef SYSTEMINLINE}inline;{$endif} begin - Result := Word((AValue shr 8) or (AValue shl 8)); + Result := ((AValue shr 8) or (AValue shl 8)) and $ffff; end; {$endif} diff --git a/rtl/x86_64/x86_64.inc b/rtl/x86_64/x86_64.inc index a8edf06bc3..e64256e987 100644 --- a/rtl/x86_64/x86_64.inc +++ b/rtl/x86_64/x86_64.inc @@ -1021,13 +1021,13 @@ function SwapEndian(const AValue: SmallInt): SmallInt;{$ifdef SYSTEMINLINE}inlin { is turned into "longint(AValue) shr 8", so if AValue < 0 then } { the sign bits from the upper 16 bits are shifted in rather than } { zeroes. } - Result := SmallInt((Word(AValue) shr 8) or (Word(AValue) shl 8)); + Result := ((Word(AValue) shr 8) or (Word(AValue) shl 8)) and $ffff; end; function SwapEndian(const AValue: Word): Word;{$ifdef SYSTEMINLINE}inline;{$endif} begin - Result := Word((AValue shr 8) or (AValue shl 8)); + Result := ((AValue shr 8) or (AValue shl 8)) and $ffff; end; diff --git a/tests/tbs/tb0676.pp b/tests/tbs/tb0676.pp new file mode 100644 index 0000000000..9abb2a5d0a --- /dev/null +++ b/tests/tbs/tb0676.pp @@ -0,0 +1,14 @@ +{ %NORUN } + +program tb0676; + +{$warn 4110 error} + +begin + SwapEndian(UInt16($1234)); + SwapEndian(Int16($8765)); + SwapEndian(UInt32($12345678)); + SwapEndian(Int32($87654321)); + SwapEndian(UInt64($1234567887654321)); + SwapEndian(Int64($8765432112345678)); +end.