Skip to content

Commit e7cbf1d

Browse files
committed
Add SWIFT_ABI_DEFAULT_REFERENCE_POISON_DEBUG_VALUE
Poison sentinel value recognized by LLDB as a former reference to a potentially deinitialized object. It uses no spare bits and cannot point to readable memory. This is not ABI per-se but does stay in-sync with LLDB. If it becomes out-of-sync, then users won't see a friendly diagnostic when inspecting references past their lifetime.
1 parent 7f5c569 commit e7cbf1d

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

lib/IRGen/SwiftTargetInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ SwiftTargetInfo::SwiftTargetInfo(
158158
SWIFT_ABI_DEFAULT_OBJC_RESERVED_BITS_MASK);
159159
setToMask(FunctionPointerSpareBits, numPointerBits,
160160
SWIFT_ABI_DEFAULT_FUNCTION_SPARE_BITS_MASK);
161+
if (numPointerBits == 64) {
162+
ReferencePoisonDebugValue =
163+
SWIFT_ABI_DEFAULT_REFERENCE_POISON_DEBUG_VALUE_64;
164+
} else {
165+
ReferencePoisonDebugValue =
166+
SWIFT_ABI_DEFAULT_REFERENCE_POISON_DEBUG_VALUE_32;
167+
}
161168
}
162169

163170
SwiftTargetInfo SwiftTargetInfo::get(IRGenModule &IGM) {

lib/IRGen/SwiftTargetInfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ class SwiftTargetInfo {
8888
/// Changes to this must be kept in sync with swift/Runtime/Metadata.h.
8989
uint64_t LeastValidPointerValue;
9090

91+
/// Poison sentinel value recognized by LLDB as a former reference to a
92+
/// potentially deinitialized object. It uses no spare bits and cannot point
93+
/// to readable memory.
94+
uint64_t ReferencePoisonDebugValue;
95+
9196
/// The maximum number of scalars that we allow to be returned directly.
9297
unsigned MaxScalarsForDirectResult = 3;
9398

stdlib/public/SwiftShims/System.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@
6969
// Only the bottom 56 bits are used, and heap objects are eight-byte-aligned.
7070
#define SWIFT_ABI_DEFAULT_64BIT_SPARE_BITS_MASK 0xFF00000000000007ULL
7171

72+
// Poison sentinel value recognized by LLDB as a former reference to a
73+
// potentially deinitialized object. It uses no spare bits and cannot point to
74+
// readable memory.
75+
//
76+
// This is not ABI per-se but does stay in-sync with LLDB. If it becomes
77+
// out-of-sync, then users won't see a friendly diagnostic when inspecting
78+
// references past their lifetime.
79+
#define SWIFT_ABI_DEFAULT_REFERENCE_POISON_DEBUG_VALUE_32 0x00000880U
80+
#define SWIFT_ABI_DEFAULT_REFERENCE_POISON_DEBUG_VALUE_64 0x0000000000000880ULL
81+
7282
/*********************************** i386 *************************************/
7383

7484
// Heap objects are pointer-aligned, so the low two bits are unused.

0 commit comments

Comments
 (0)