Skip to content

Get CFString.test to pass #3370

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

Merged
merged 2 commits into from
Oct 8, 2021
Merged
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
54 changes: 44 additions & 10 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ static bool ContainsGenericTypeParameter(swift::Demangle::NodePointer node) {
static uint32_t collectTypeInfo(SwiftASTContext *module_holder,
swift::Demangle::Demangler &dem,
swift::Demangle::NodePointer node,
bool &unresolved_typealias,
bool generic_walk = false) {
LLDB_SCOPED_TIMER();
if (!node)
Expand Down Expand Up @@ -1073,7 +1074,8 @@ static uint32_t collectTypeInfo(SwiftASTContext *module_holder,
if ((type_class & eTypeClassBuiltin)) {
swift_flags &= ~eTypeIsStructUnion;
swift_flags |= collectTypeInfo(
module_holder, dem, GetClangTypeNode(clang_type, dem, module_holder));
module_holder, dem, GetClangTypeNode(clang_type, dem, module_holder),
unresolved_typealias);
return;
}
};
Expand Down Expand Up @@ -1253,6 +1255,11 @@ static uint32_t collectTypeInfo(SwiftASTContext *module_holder,
collect_clang_type(clang_type);
return swift_flags;
}
if (!node_clangtype.first) {
// If this is a typealias defined in the expression evaluator,
// then we don't have debug info to resolve it from.
unresolved_typealias = true;
}
swift_flags |= collectTypeInfo(module_holder, dem, node_clangtype.first,
generic_walk);
return swift_flags;
Expand All @@ -1267,7 +1274,8 @@ static uint32_t collectTypeInfo(SwiftASTContext *module_holder,

// Visit the child nodes.
for (unsigned i = 0; i < node->getNumChildren(); ++i)
swift_flags |= collectTypeInfo(module_holder, dem, node->getChild(i), generic_walk);
swift_flags |= collectTypeInfo(module_holder, dem, node->getChild(i),
unresolved_typealias, generic_walk);

return swift_flags;
}
Expand Down Expand Up @@ -2058,7 +2066,16 @@ uint32_t TypeSystemSwiftTypeRef::GetTypeInfo(
using namespace swift::Demangle;
Demangler dem;
NodePointer node = dem.demangleSymbol(AsMangledName(type));
return collectTypeInfo(m_swift_ast_context, dem, node);
bool unresolved_typealias = false;
uint32_t flags =
collectTypeInfo(m_swift_ast_context, dem, node, unresolved_typealias);
if (unresolved_typealias) {
// If this is a typealias defined in the expression evaluator,
// then we don't have debug info to resolve it from.
return m_swift_ast_context->GetTypeInfo(ReconstructType(type),
pointee_or_element_clang_type);
}
return flags;
};

VALIDATE_AND_RETURN(impl, GetTypeInfo, type, (ReconstructType(type), nullptr),
Expand Down Expand Up @@ -3202,6 +3219,16 @@ bool TypeSystemSwiftTypeRef::DumpTypeValue(
ReconstructType(type), s, format, data, data_offset, data_byte_size,
bitfield_bit_size, bitfield_bit_offset, exe_scope, is_base_class);
}
case Node::Kind::TypeAlias:
case Node::Kind::BoundGenericTypeAlias: {
// This means we have an unresolved type alias that even
// SwiftASTContext couldn't resolve. This happens for ObjC
// typedefs such as CFString in the REPL. More investigation is
// needed.
return m_swift_ast_context->DumpTypeValue(
ReconstructType(type), s, format, data, data_offset, data_byte_size,
bitfield_bit_size, bitfield_bit_offset, exe_scope, is_base_class);
}
default:
assert(false && "Unhandled node kind");
LLDB_LOGF(GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
Expand Down Expand Up @@ -3470,16 +3497,23 @@ TypeSystemSwiftTypeRef::GetGenericArgumentType(opaque_compiler_type_t type,
(ReconstructType(type), idx));
}
#ifndef NDEBUG
bool TypeSystemSwiftTypeRef::ShouldSkipValidation(opaque_compiler_type_t type) { \
// NSNotificationName is a typedef to a NSString in clang type, but it's a
bool TypeSystemSwiftTypeRef::ShouldSkipValidation(opaque_compiler_type_t type) {
auto mangled_name = GetMangledTypeName(type);
// NSNotificationName is a typedef to a NSString in clang type, but it's a
// struct in SwiftASTContext. Skip validation in this case.
if (mangled_name == "$sSo18NSNotificationNameaD")
return true;

// $s10Foundation12NotificationV4NameaD is a typealias to NSNotificationName,
// so we skip validation in that casse as well.
auto mangled_name = GetMangledTypeName(type);
if (mangled_name == "$sSo18NSNotificationNameaD" ||
mangled_name == "$s10Foundation12NotificationV4NameaD" ||
mangled_name == "$sSo9NSDecimalaD")
return true;
if (mangled_name == "$s10Foundation12NotificationV4NameaD")
return true;
if (mangled_name == "$sSo9NSDecimalaD")
return true;
// Reconstruct($sSo11CFStringRefaD) returns a non-typealias type, breaking
// isTypedef().
if (mangled_name == "$sSo11CFStringRefaD")
return true;

// We skip validation when dealing with a builtin type since builtins are
// considered type aliases by Swift, which we're deviating from since
Expand Down