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

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 6 15:37:57 PDT 2018


MaskRay created this revision.
MaskRay added a reviewer: ruiu.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.

To be consistent with other files where only SignExtend64 is used.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D50366

Files:
  ELF/Target.h


Index: ELF/Target.h
===================================================================
--- ELF/Target.h
+++ 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.159413.patch
Type: text/x-patch
Size: 1323 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180806/0bfb53f2/attachment.bin>


More information about the llvm-commits mailing list