mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-14 15:38:57 +00:00
Avoid overflowing a signed integer which triggers undefined behaviour.
Overflowing an unsigned integer is fine and behaves as you would expect. Also fix a pasto, allowing SignExtend64 to take a 64-bit argument. llvm-svn: 100517
This commit is contained in:
parent
cbfa9139eb
commit
37cb8c0742
@ -459,14 +459,14 @@ inline int64_t abs64(int64_t x) {
|
||||
|
||||
/// SignExtend32 - Sign extend B-bit number x to 32-bit int.
|
||||
/// Usage int32_t r = SignExtend32<5>(x);
|
||||
template <unsigned B> inline int32_t SignExtend32(int32_t x) {
|
||||
return (x << (32 - B)) >> (32 - B);
|
||||
template <unsigned B> inline int32_t SignExtend32(uint32_t x) {
|
||||
return int32_t(x << (32 - B)) >> (32 - B);
|
||||
}
|
||||
|
||||
/// SignExtend64 - Sign extend B-bit number x to 64-bit int.
|
||||
/// Usage int64_t r = SignExtend64<5>(x);
|
||||
template <unsigned B> inline int64_t SignExtend64(int32_t x) {
|
||||
return (x << (64 - B)) >> (64 - B);
|
||||
template <unsigned B> inline int64_t SignExtend64(uint64_t x) {
|
||||
return int64_t(x << (64 - B)) >> (64 - B);
|
||||
}
|
||||
|
||||
} // End llvm namespace
|
||||
|
Loading…
x
Reference in New Issue
Block a user