Skip to content

Avoid calling Node::deepEquals if one of the node pointers is null. #10201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: stable/20240723
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ static bool IsSwiftAsyncFunctionSymbol(swift::Demangle::NodePointer node) {
Node::Kind::AsyncAnnotation});
}

static bool NullSafeNodeDeepEquals(swift::Demangle::NodePointer node1,
swift::Demangle::NodePointer node2) {
if (!node1 || !node2) {
return node1 == node2;
}
return Node::deepEquals(node1, node2);
}

/// Returns true if closure1 and closure2 have the same number, type, and
/// parent closures / function.
static bool
Expand All @@ -112,12 +120,12 @@ AreFuncletsOfSameAsyncClosure(swift::Demangle::NodePointer closure1,
using namespace swift::Demangle;
NodePointer closure1_number = childAtPath(closure1, Node::Kind::Number);
NodePointer closure2_number = childAtPath(closure2, Node::Kind::Number);
if (!Node::deepEquals(closure1_number, closure2_number))
if (!NullSafeNodeDeepEquals(closure1_number, closure2_number))
return false;

NodePointer closure1_type = childAtPath(closure1, Node::Kind::Type);
NodePointer closure2_type = childAtPath(closure2, Node::Kind::Type);
if (!Node::deepEquals(closure1_type, closure2_type))
if (!NullSafeNodeDeepEquals(closure1_type, closure2_type))
return false;

// Because the tree is inverted, a parent closure (in swift code) is a child
Expand All @@ -126,14 +134,14 @@ AreFuncletsOfSameAsyncClosure(swift::Demangle::NodePointer closure1,
childAtPath(closure1, Node::Kind::ExplicitClosure);
NodePointer closure2_parent =
childAtPath(closure2, Node::Kind::ExplicitClosure);
if (!Node::deepEquals(closure1_parent, closure2_parent))
if (!NullSafeNodeDeepEquals(closure1_parent, closure2_parent))
return false;

// If there are no ExplicitClosure as parents, there may still be a
// Function. Also check that they are identical.
NodePointer closure1_function = childAtPath(closure1, Node::Kind::Function);
NodePointer closure2_function = childAtPath(closure2, Node::Kind::Function);
return Node::deepEquals(closure1_function, closure2_function);
return NullSafeNodeDeepEquals(closure1_function, closure2_function);
}

SwiftLanguageRuntime::FuncletComparisonResult
Expand Down Expand Up @@ -172,7 +180,7 @@ SwiftLanguageRuntime::AreFuncletsOfSameAsyncFunction(llvm::StringRef name1,
// Otherwise, find the corresponding function and compare the two.
NodePointer function1 = childAtPath(node1, Node::Kind::Function);
NodePointer function2 = childAtPath(node2, Node::Kind::Function);
return Node::deepEquals(function1, function2)
return NullSafeNodeDeepEquals(function1, function2)
? FuncletComparisonResult::SameAsyncFunction
: FuncletComparisonResult::DifferentAsyncFunctions;
}
Expand Down