Skip to content

Commit 3a04b39

Browse files
[lldb][nfc] Expose and isolate swift customization for stack ID comparison
The code moved in this patch is a swift customization, even though it is missing the customization markers. This simple refactor should also make it clear that there is a bug in this function: it is not symmetric.
1 parent d282f3f commit 3a04b39

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

lldb/source/Target/StackID.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,41 @@ bool lldb_private::operator!=(const StackID &lhs, const StackID &rhs) {
7373
return lhs_scope != rhs_scope;
7474
}
7575

76-
bool StackID::IsYounger(const StackID &lhs, const StackID &rhs,
77-
Process &process) {
76+
// BEGIN SWIFT
77+
enum class HeapCFAComparisonResult { Younger, Older, NoOpinion };
78+
/// If at least one of the stack IDs (lhs, rhs) is a heap CFA, perform the
79+
/// swift-specific async frame comparison. Otherwise, returns NoOpinion.
80+
static HeapCFAComparisonResult
81+
IsYoungerHeapCFAs(const StackID &lhs, const StackID &rhs, Process &process) {
82+
const bool lhs_cfa_on_stack = lhs.IsCFAOnStack(process);
83+
const bool rhs_cfa_on_stack = rhs.IsCFAOnStack(process);
84+
if (lhs_cfa_on_stack && rhs_cfa_on_stack)
85+
return HeapCFAComparisonResult::NoOpinion;
86+
7887
// FIXME: rdar://76119439
7988
// At the boundary between an async parent frame calling a regular child
8089
// frame, the CFA of the parent async function is a heap addresses, and the
8190
// CFA of concrete child function is a stack address. Therefore, if lhs is
8291
// on stack, and rhs is not, lhs is considered less than rhs, independent of
8392
// address values.
84-
if (lhs.IsCFAOnStack(process) && !rhs.IsCFAOnStack(process))
93+
if (lhs_cfa_on_stack && !rhs_cfa_on_stack)
94+
return HeapCFAComparisonResult::Younger;
95+
return HeapCFAComparisonResult::NoOpinion;
96+
}
97+
// END SWIFT
98+
99+
bool StackID::IsYounger(const StackID &lhs, const StackID &rhs,
100+
Process &process) {
101+
// BEGIN SWIFT
102+
switch (IsYoungerHeapCFAs(lhs, rhs, process)) {
103+
case HeapCFAComparisonResult::Younger:
85104
return true;
105+
case HeapCFAComparisonResult::Older:
106+
return false;
107+
case HeapCFAComparisonResult::NoOpinion:
108+
break;
109+
}
110+
// END SWIFT
86111

87112
const lldb::addr_t lhs_cfa = lhs.GetCallFrameAddress();
88113
const lldb::addr_t rhs_cfa = rhs.GetCallFrameAddress();

0 commit comments

Comments
 (0)