[PATCH] D50366: [ELF] Use MathExtras.h llvm::SignExtend64

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 6 16:51:04 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL339083: [ELF] Use MathExtras.h llvm::SignExtend64 (authored by MaskRay, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D50366

Files:
  lld/trunk/ELF/Target.h


Index: lld/trunk/ELF/Target.h
===================================================================
--- lld/trunk/ELF/Target.h
+++ lld/trunk/ELF/Target.h
@@ -13,6 +13,7 @@
 #include "InputSection.h"
 #include "lld/Common/ErrorHandler.h"
 #include "llvm/Object/ELF.h"
+#include "llvm/Support/MathExtras.h"
 
 namespace lld {
 std::string toString(elf::RelType Type);
@@ -189,14 +190,9 @@
         Twine(Max).str() + "]" + Hint);
 }
 
-// Sign-extend Nth bit all the way to MSB.
-inline int64_t signExtend(uint64_t V, int N) {
-  return int64_t(V << (64 - N)) >> (64 - N);
-}
-
 // Make sure that V can be represented as an N bit signed integer.
 inline void checkInt(uint8_t *Loc, int64_t V, int N, RelType Type) {
-  if (V != signExtend(V, N))
+  if (V != llvm::SignExtend64(V, N))
     reportRangeError(Loc, Type, Twine(V), llvm::minIntN(N), llvm::maxIntN(N));
 }
 
@@ -210,7 +206,7 @@
 inline void checkIntUInt(uint8_t *Loc, uint64_t V, int N, RelType Type) {
   // For the error message we should cast V to a signed integer so that error
   // messages show a small negative value rather than an extremely large one
-  if (V != (uint64_t)signExtend(V, N) && (V >> N) != 0)
+  if (V != (uint64_t)llvm::SignExtend64(V, N) && (V >> N) != 0)
     reportRangeError(Loc, Type, Twine((int64_t)V), llvm::minIntN(N),
                      llvm::maxIntN(N));
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50366.159433.patch
Type: text/x-patch
Size: 1353 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180806/8eea57fb/attachment.bin>


More information about the llvm-commits mailing list