[llvm-commits] [llvm] r100233 - in /llvm/trunk: ./ include/llvm/Support/ lib/Target/ARM/ lib/Target/ARM/Disassembler/ test/MC/Disassembler/ utils/TableGen/

Jakob Stoklund Olesen stoklund at 2pi.dk
Sun Apr 4 18:31:34 PDT 2010


On Apr 2, 2010, at 3:27 PM, Johnny Chen wrote:

> Modified: llvm/trunk/include/llvm/Support/MathExtras.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MathExtras.h?rev=100233&r1=100232&r2=100233&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Support/MathExtras.h (original)
> +++ llvm/trunk/include/llvm/Support/MathExtras.h Fri Apr  2 17:27:38 2010
> @@ -457,6 +457,18 @@
>   return (x < 0) ? -x : 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);
> +}
> +
> +/// 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) {

Should be (int64_t x).

> +  return (x << (64 - B)) >> (64 - B);
> +}
> +

I wonder if this is safe? These functions depend on signed overflow which is undefined behavior.





More information about the llvm-commits mailing list