[PATCH] [UBSan][MIPS] Use unsigned value while bit shifting on MIPS
Sagar Thakur
Sagar.Thakur at imgtec.com
Tue Apr 28 03:17:41 PDT 2015
Simplified code and made it platform-independent.
REPOSITORY
rL LLVM
http://reviews.llvm.org/D9247
Files:
lib/ubsan/ubsan_value.cc
Index: lib/ubsan/ubsan_value.cc
===================================================================
--- lib/ubsan/ubsan_value.cc
+++ lib/ubsan/ubsan_value.cc
@@ -12,6 +12,7 @@
//
//===----------------------------------------------------------------------===//
+#include <stdlib.h>
#include "ubsan_platform.h"
#if CAN_SANITIZE_UB
#include "ubsan_value.h"
@@ -27,7 +28,16 @@
// to SIntMax.
const unsigned ExtraBits =
sizeof(SIntMax) * 8 - getType().getIntegerBitWidth();
- return SIntMax(Val) << ExtraBits >> ExtraBits;
+ UIntMax Value;
+ if(getType().getIntegerBitWidth() == 32)
+ Value = UIntMax(abs(Val));
+ else
+ Value = UIntMax(llabs(Val));
+ Value = Value << ExtraBits >> ExtraBits;
+ uptr Mask = 1UL << (getType().getIntegerBitWidth() - 1);
+ if(Mask & Val)
+ return -(SIntMax(Value));
+ return SIntMax(Value);
}
if (getType().getIntegerBitWidth() == 64)
return *reinterpret_cast<s64*>(Val);
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9247.24535.patch
Type: text/x-patch
Size: 972 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150428/b1f19438/attachment.bin>
More information about the llvm-commits
mailing list