[Runtime] Fix swift_retainCount for deiniting objects and BridgeObject tagged values. Make swift_bridgeObjectRetain/Release bail out early for tagged values.

The Allocations Instrument overrides swift_retain with a function that records the retain count by calling swift_retainCount. Its assert for bits.getIsDeiniting() is incorrect in that case, so remove it.

The recent change to ObjC tagged pointer bits on x86-64 also caused the various bridgeObjectRetain/Release functions to call through to swift_retain for BridgeObject tagged values on Mac. swift_retain ignored those values so there was no functional change, except when Instruments overrode it and passed them to swift_retainCount, which tried to dereference them and crashed. Modify bridgeObjectRetain/Release to bail out early again. Also modify swift_retainCount to ignore those values in case anything else expects retainCount to work on any pointer swift_retain accepts.

rdar://problem/45102538
This commit is contained in:
Mike Ash
2018-10-09 10:04:06 -04:00
parent 80d765034c
commit 1afd079b78
3 changed files with 18 additions and 11 deletions

View File

@@ -365,7 +365,9 @@ void swift::swift_nonatomic_release_n(HeapObject *object, uint32_t n) {
}
size_t swift::swift_retainCount(HeapObject *object) {
return object->refCounts.getCount();
if (isValidPointerForNativeRetain(object))
return object->refCounts.getCount();
return 0;
}
size_t swift::swift_unownedRetainCount(HeapObject *object) {