[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
Fri Oct 13 15:45:02 PDT 2017
xiaobai updated this revision to Diff 118981.
xiaobai added a comment.
Addressed comments and fixed incorrect test.
https://reviews.llvm.org/D38871
Files:
lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s
Index: test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s
===================================================================
--- test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s
+++ test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s
@@ -1,5 +1,5 @@
// RUN: llvm-mc -triple i686-windows -filetype obj -o %t.obj %s
-// RUN: llvm-rtdyld -triple i686-windows -dummy-extern _printf=0xfffffffd -dummy-extern _OutputDebugStringA at 4=0xfffffffe -dummy-extern _ExitProcess at 4=0xffffffff -verify -check=%s %t.obj
+// RUN: llvm-rtdyld -triple i686-windows -dummy-extern _printf=0x7ffffffd -dummy-extern _OutputDebugStringA at 4=0x7ffffffe -dummy-extern _ExitProcess at 4=0x7fffffff -verify -check=%s %t.obj
.text
@@ -41,13 +41,13 @@
.align 4
__imp__OutputDebugStringA:
.long "_OutputDebugStringA at 4" // IMAGE_REL_I386_DIR32
-# rtdyld-check: *{4}__imp__OutputDebugStringA = 0xfffffffe
+# rtdyld-check: *{4}__imp__OutputDebugStringA = 0x7ffffffe
.global __imp__ExitProcess
.align 4
__imp__ExitProcess:
.long "_ExitProcess at 4" // IMAGE_REL_I386_DIR32
-# rtdyld-check: *{4}__imp__ExitProcess = 0xffffffff
+# rtdyld-check: *{4}__imp__ExitProcess = 0x7fffffff
.global string
.align 1
Index: lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
===================================================================
--- lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
+++ lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
@@ -144,10 +144,7 @@
? Value
: Sections[RE.Sections.SectionA].getLoadAddressWithOffset(
RE.Addend);
- assert(static_cast<int32_t>(Result) <= INT32_MAX &&
- "relocation overflow");
- assert(static_cast<int32_t>(Result) >= INT32_MIN &&
- "relocation underflow");
+ assert(Result <= UINT32_MAX && "relocation overflow");
DEBUG(dbgs() << "\t\tOffset: " << RE.Offset
<< " RelType: IMAGE_REL_I386_DIR32"
<< " TargetSection: " << RE.Sections.SectionA
@@ -161,10 +158,7 @@
uint64_t Result =
Sections[RE.Sections.SectionA].getLoadAddressWithOffset(RE.Addend) -
Sections[0].getLoadAddress();
- assert(static_cast<int32_t>(Result) <= INT32_MAX &&
- "relocation overflow");
- assert(static_cast<int32_t>(Result) >= INT32_MIN &&
- "relocation underflow");
+ assert(Result <= UINT32_MAX && "relocation overflow");
DEBUG(dbgs() << "\t\tOffset: " << RE.Offset
<< " RelType: IMAGE_REL_I386_DIR32NB"
<< " TargetSection: " << RE.Sections.SectionA
@@ -178,9 +172,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"
@@ -191,21 +185,17 @@
}
case COFF::IMAGE_REL_I386_SECTION:
// 16-bit section index of the section that contains the target.
- assert(static_cast<int32_t>(RE.SectionID) <= INT16_MAX &&
+ assert(static_cast<uint32_t>(RE.SectionID) <= UINT16_MAX &&
"relocation overflow");
- assert(static_cast<int32_t>(RE.SectionID) >= INT16_MIN &&
- "relocation underflow");
DEBUG(dbgs() << "\t\tOffset: " << RE.Offset
<< " RelType: IMAGE_REL_I386_SECTION Value: " << RE.SectionID
<< '\n');
writeBytesUnaligned(RE.SectionID, Target, 2);
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 &&
+ assert(static_cast<uint64_t>(RE.Addend) <= UINT32_MAX &&
"relocation overflow");
- assert(static_cast<int32_t>(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.118981.patch
Type: text/x-patch
Size: 4449 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171013/f4c83c11/attachment.bin>
More information about the llvm-commits
mailing list