1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

ExecutionEngine: make COFF Thumb2 assertions non-tautological

The overflow detection assertions were tautological due to truncation.
Adjust them to no longer be tautological.

Patch by Alex Langford!

llvm-svn: 316303
This commit is contained in:
Saleem Abdulrasool 2017-10-22 20:51:25 +00:00
parent a621a9dcb4
commit db58d93031

View File

@ -186,10 +186,7 @@ public:
? Value ? Value
: Sections[RE.Sections.SectionA].getLoadAddressWithOffset(RE.Addend); : Sections[RE.Sections.SectionA].getLoadAddressWithOffset(RE.Addend);
Result |= ISASelectionBit; Result |= ISASelectionBit;
assert(static_cast<int32_t>(Result) <= INT32_MAX && assert(Result <= UINT32_MAX && "relocation overflow");
"relocation overflow");
assert(static_cast<int32_t>(Result) >= INT32_MIN &&
"relocation underflow");
DEBUG(dbgs() << "\t\tOffset: " << RE.Offset DEBUG(dbgs() << "\t\tOffset: " << RE.Offset
<< " RelType: IMAGE_REL_ARM_ADDR32" << " RelType: IMAGE_REL_ARM_ADDR32"
<< " TargetSection: " << RE.Sections.SectionA << " TargetSection: " << RE.Sections.SectionA
@ -202,10 +199,7 @@ public:
// NOTE: use Section[0].getLoadAddress() as an approximation of ImageBase // NOTE: use Section[0].getLoadAddress() as an approximation of ImageBase
uint64_t Result = Sections[RE.Sections.SectionA].getLoadAddress() - uint64_t Result = Sections[RE.Sections.SectionA].getLoadAddress() -
Sections[0].getLoadAddress() + RE.Addend; Sections[0].getLoadAddress() + RE.Addend;
assert(static_cast<int32_t>(Result) <= INT32_MAX && assert(Result <= UINT32_MAX && "relocation overflow");
"relocation overflow");
assert(static_cast<int32_t>(Result) >= INT32_MIN &&
"relocation underflow");
DEBUG(dbgs() << "\t\tOffset: " << RE.Offset DEBUG(dbgs() << "\t\tOffset: " << RE.Offset
<< " RelType: IMAGE_REL_ARM_ADDR32NB" << " RelType: IMAGE_REL_ARM_ADDR32NB"
<< " TargetSection: " << RE.Sections.SectionA << " TargetSection: " << RE.Sections.SectionA
@ -216,10 +210,8 @@ public:
} }
case COFF::IMAGE_REL_ARM_SECTION: case COFF::IMAGE_REL_ARM_SECTION:
// 16-bit section index of the section that contains the target. // 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"); "relocation overflow");
assert(static_cast<int32_t>(RE.SectionID) >= INT16_MIN &&
"relocation underflow");
DEBUG(dbgs() << "\t\tOffset: " << RE.Offset DEBUG(dbgs() << "\t\tOffset: " << RE.Offset
<< " RelType: IMAGE_REL_ARM_SECTION Value: " << RE.SectionID << " RelType: IMAGE_REL_ARM_SECTION Value: " << RE.SectionID
<< '\n'); << '\n');
@ -227,10 +219,8 @@ public:
break; break;
case COFF::IMAGE_REL_ARM_SECREL: case COFF::IMAGE_REL_ARM_SECREL:
// 32-bit offset of the target from the beginning of its section. // 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"); "relocation overflow");
assert(static_cast<int32_t>(RE.Addend) >= INT32_MIN &&
"relocation underflow");
DEBUG(dbgs() << "\t\tOffset: " << RE.Offset DEBUG(dbgs() << "\t\tOffset: " << RE.Offset
<< " RelType: IMAGE_REL_ARM_SECREL Value: " << RE.Addend << " RelType: IMAGE_REL_ARM_SECREL Value: " << RE.Addend
<< '\n'); << '\n');
@ -240,10 +230,7 @@ public:
// 32-bit VA of the target applied to a contiguous MOVW+MOVT pair. // 32-bit VA of the target applied to a contiguous MOVW+MOVT pair.
uint64_t Result = uint64_t Result =
Sections[RE.Sections.SectionA].getLoadAddressWithOffset(RE.Addend); Sections[RE.Sections.SectionA].getLoadAddressWithOffset(RE.Addend);
assert(static_cast<int32_t>(Result) <= INT32_MAX && assert(Result <= UINT32_MAX && "relocation overflow");
"relocation overflow");
assert(static_cast<int32_t>(Result) >= INT32_MIN &&
"relocation underflow");
DEBUG(dbgs() << "\t\tOffset: " << RE.Offset DEBUG(dbgs() << "\t\tOffset: " << RE.Offset
<< " RelType: IMAGE_REL_ARM_MOV32T" << " RelType: IMAGE_REL_ARM_MOV32T"
<< " TargetSection: " << RE.Sections.SectionA << " TargetSection: " << RE.Sections.SectionA
@ -271,9 +258,9 @@ public:
// The most significant 20-bits of the signed 21-bit relative displacement // The most significant 20-bits of the signed 21-bit relative displacement
uint64_t Value = uint64_t Value =
RE.Addend - (Sections[RE.SectionID].getLoadAddress() + RE.Offset) - 4; RE.Addend - (Sections[RE.SectionID].getLoadAddress() + RE.Offset) - 4;
assert(static_cast<int32_t>(RE.Addend) <= INT32_MAX && assert(static_cast<int64_t>(RE.Addend) <= INT32_MAX &&
"relocation overflow"); "relocation overflow");
assert(static_cast<int32_t>(RE.Addend) >= INT32_MIN && assert(static_cast<int64_t>(RE.Addend) >= INT32_MIN &&
"relocation underflow"); "relocation underflow");
DEBUG(dbgs() << "\t\tOffset: " << RE.Offset DEBUG(dbgs() << "\t\tOffset: " << RE.Offset
<< " RelType: IMAGE_REL_ARM_BRANCH20T" << " RelType: IMAGE_REL_ARM_BRANCH20T"
@ -286,9 +273,9 @@ public:
// The most significant 24-bits of the signed 25-bit relative displacement // The most significant 24-bits of the signed 25-bit relative displacement
uint64_t Value = uint64_t Value =
RE.Addend - (Sections[RE.SectionID].getLoadAddress() + RE.Offset) - 4; RE.Addend - (Sections[RE.SectionID].getLoadAddress() + RE.Offset) - 4;
assert(static_cast<int32_t>(RE.Addend) <= INT32_MAX && assert(static_cast<int64_t>(RE.Addend) <= INT32_MAX &&
"relocation overflow"); "relocation overflow");
assert(static_cast<int32_t>(RE.Addend) >= INT32_MIN && assert(static_cast<int64_t>(RE.Addend) >= INT32_MIN &&
"relocation underflow"); "relocation underflow");
DEBUG(dbgs() << "\t\tOffset: " << RE.Offset DEBUG(dbgs() << "\t\tOffset: " << RE.Offset
<< " RelType: IMAGE_REL_ARM_BRANCH24T" << " RelType: IMAGE_REL_ARM_BRANCH24T"
@ -301,9 +288,9 @@ public:
// The most significant 24-bits of the signed 25-bit relative displacement // The most significant 24-bits of the signed 25-bit relative displacement
uint64_t Value = uint64_t Value =
RE.Addend - (Sections[RE.SectionID].getLoadAddress() + RE.Offset) - 4; RE.Addend - (Sections[RE.SectionID].getLoadAddress() + RE.Offset) - 4;
assert(static_cast<int32_t>(RE.Addend) <= INT32_MAX && assert(static_cast<int64_t>(RE.Addend) <= INT32_MAX &&
"relocation overflow"); "relocation overflow");
assert(static_cast<int32_t>(RE.Addend) >= INT32_MIN && assert(static_cast<int64_t>(RE.Addend) >= INT32_MIN &&
"relocation underflow"); "relocation underflow");
DEBUG(dbgs() << "\t\tOffset: " << RE.Offset DEBUG(dbgs() << "\t\tOffset: " << RE.Offset
<< " RelType: IMAGE_REL_ARM_BLX23T" << " RelType: IMAGE_REL_ARM_BLX23T"
@ -321,4 +308,3 @@ public:
} }
#endif #endif