[Builtin] Add _isValidAddress pointer-value check.

And adopt it for StringGuts, as it is more robust on 32-bit systems.
This commit is contained in:
Michael Ilseman
2018-01-21 09:01:48 -08:00
parent b8d8949166
commit b61b53330f
2 changed files with 10 additions and 4 deletions

View File

@@ -29,8 +29,6 @@ import SwiftShims
// FIXME: what about ppc64 and s390x?
//
@_fixed_layout
public // FIXME
struct _StringGuts {
@@ -78,7 +76,7 @@ extension _StringGuts {
} else if _object.isUnmanaged {
} else if _object.isCocoa {
if _object.isContiguous {
_sanityCheck(_otherBits != 0) // TODO: in ABI's address space
_sanityCheck(_isValidAddress(_otherBits))
} else {
_sanityCheck(_otherBits == 0)
}
@@ -238,7 +236,7 @@ extension _StringGuts {
@inline(__always)
get {
_sanityCheck(_object.isContiguousCocoa)
_sanityCheck(Int(bitPattern: _otherBits) >= 1) // TODO: ABI's min address
_sanityCheck(_isValidAddress(_otherBits))
return UnsafeRawPointer(
bitPattern: _otherBits
)._unsafelyUnwrappedUnchecked