diff options
author | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2010-04-06 03:12:43 +0000 |
---|---|---|
committer | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2010-04-06 03:12:43 +0000 |
commit | adc6e06ff0c5950abda86574c2da1fc6b863b75c (patch) | |
tree | c20b07a8e44760901a560f6cd951616db54b3eb4 /include/llvm/Support/MathExtras.h | |
parent | 3d3238699280ec8ccd5c5579bc04a48229abe7ef (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100517 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/MathExtras.h')
-rw-r--r-- | include/llvm/Support/MathExtras.h | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/include/llvm/Support/MathExtras.h b/include/llvm/Support/MathExtras.h index f56241c579..80d11ae062 100644 --- a/include/llvm/Support/MathExtras.h +++ b/include/llvm/Support/MathExtras.h @@ -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 |