[PATCH] D38871: [ExecutionEngine] Modify static_casts to not be tautological in some COFF i386 relocations

Alex Langford via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 12 18:39:03 PDT 2017


xiaobai created this revision.

I'm pretty sure an int32_t will always be between INT32_MAX and
INT32_MIN, inclusive.


https://reviews.llvm.org/D38871

Files:
  lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h


Index: lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
===================================================================
--- lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
+++ lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
@@ -144,9 +144,9 @@
               ? Value
               : Sections[RE.Sections.SectionA].getLoadAddressWithOffset(
                     RE.Addend);
-      assert(static_cast<int32_t>(Result) <= INT32_MAX &&
+      assert(static_cast<int64_t>(Result) <= INT32_MAX &&
              "relocation overflow");
-      assert(static_cast<int32_t>(Result) >= INT32_MIN &&
+      assert(static_cast<int64_t>(Result) >= INT32_MIN &&
              "relocation underflow");
       DEBUG(dbgs() << "\t\tOffset: " << RE.Offset
                    << " RelType: IMAGE_REL_I386_DIR32"
@@ -161,9 +161,9 @@
       uint64_t Result =
           Sections[RE.Sections.SectionA].getLoadAddressWithOffset(RE.Addend) -
           Sections[0].getLoadAddress();
-      assert(static_cast<int32_t>(Result) <= INT32_MAX &&
+      assert(static_cast<int64_t>(Result) <= INT32_MAX &&
              "relocation overflow");
-      assert(static_cast<int32_t>(Result) >= INT32_MIN &&
+      assert(static_cast<int64_t>(Result) >= INT32_MIN &&
              "relocation underflow");
       DEBUG(dbgs() << "\t\tOffset: " << RE.Offset
                    << " RelType: IMAGE_REL_I386_DIR32NB"
@@ -178,9 +178,9 @@
                             ? Value
                             : Sections[RE.Sections.SectionA].getLoadAddress();
       Result = Result - Section.getLoadAddress() + RE.Addend - 4 - RE.Offset;
-      assert(static_cast<int32_t>(Result) <= INT32_MAX &&
+      assert(static_cast<int64_t>(Result) <= INT32_MAX &&
              "relocation overflow");
-      assert(static_cast<int32_t>(Result) >= INT32_MIN &&
+      assert(static_cast<int64_t>(Result) >= INT32_MIN &&
              "relocation underflow");
       DEBUG(dbgs() << "\t\tOffset: " << RE.Offset
                    << " RelType: IMAGE_REL_I386_REL32"
@@ -202,10 +202,8 @@
       break;
     case COFF::IMAGE_REL_I386_SECREL:
       // 32-bit offset of the target from the beginning of its section.
-      assert(static_cast<int32_t>(RE.Addend) <= INT32_MAX &&
-             "relocation overflow");
-      assert(static_cast<int32_t>(RE.Addend) >= INT32_MIN &&
-             "relocation underflow");
+      assert(RE.Addend <= INT32_MAX && "relocation overflow");
+      assert(RE.Addend >= INT32_MIN && "relocation underflow");
       DEBUG(dbgs() << "\t\tOffset: " << RE.Offset
                    << " RelType: IMAGE_REL_I386_SECREL Value: " << RE.Addend
                    << '\n');


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38871.118875.patch
Type: text/x-patch
Size: 2699 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171013/4c934e4b/attachment.bin>


More information about the llvm-commits mailing list