Skip to content

Commit bef9d10

Browse files
Merge pull request #3370 from adrian-prantl/cfstring
Get CFString.test to pass
2 parents 65a4dde + 9c36102 commit bef9d10

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,7 @@ static bool ContainsGenericTypeParameter(swift::Demangle::NodePointer node) {
10421042
static uint32_t collectTypeInfo(SwiftASTContext *module_holder,
10431043
swift::Demangle::Demangler &dem,
10441044
swift::Demangle::NodePointer node,
1045+
bool &unresolved_typealias,
10451046
bool generic_walk = false) {
10461047
LLDB_SCOPED_TIMER();
10471048
if (!node)
@@ -1073,7 +1074,8 @@ static uint32_t collectTypeInfo(SwiftASTContext *module_holder,
10731074
if ((type_class & eTypeClassBuiltin)) {
10741075
swift_flags &= ~eTypeIsStructUnion;
10751076
swift_flags |= collectTypeInfo(
1076-
module_holder, dem, GetClangTypeNode(clang_type, dem, module_holder));
1077+
module_holder, dem, GetClangTypeNode(clang_type, dem, module_holder),
1078+
unresolved_typealias);
10771079
return;
10781080
}
10791081
};
@@ -1253,6 +1255,11 @@ static uint32_t collectTypeInfo(SwiftASTContext *module_holder,
12531255
collect_clang_type(clang_type);
12541256
return swift_flags;
12551257
}
1258+
if (!node_clangtype.first) {
1259+
// If this is a typealias defined in the expression evaluator,
1260+
// then we don't have debug info to resolve it from.
1261+
unresolved_typealias = true;
1262+
}
12561263
swift_flags |= collectTypeInfo(module_holder, dem, node_clangtype.first,
12571264
generic_walk);
12581265
return swift_flags;
@@ -1267,7 +1274,8 @@ static uint32_t collectTypeInfo(SwiftASTContext *module_holder,
12671274

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

12721280
return swift_flags;
12731281
}
@@ -2058,7 +2066,16 @@ uint32_t TypeSystemSwiftTypeRef::GetTypeInfo(
20582066
using namespace swift::Demangle;
20592067
Demangler dem;
20602068
NodePointer node = dem.demangleSymbol(AsMangledName(type));
2061-
return collectTypeInfo(m_swift_ast_context, dem, node);
2069+
bool unresolved_typealias = false;
2070+
uint32_t flags =
2071+
collectTypeInfo(m_swift_ast_context, dem, node, unresolved_typealias);
2072+
if (unresolved_typealias) {
2073+
// If this is a typealias defined in the expression evaluator,
2074+
// then we don't have debug info to resolve it from.
2075+
return m_swift_ast_context->GetTypeInfo(ReconstructType(type),
2076+
pointee_or_element_clang_type);
2077+
}
2078+
return flags;
20622079
};
20632080

20642081
VALIDATE_AND_RETURN(impl, GetTypeInfo, type, (ReconstructType(type), nullptr),
@@ -3202,6 +3219,16 @@ bool TypeSystemSwiftTypeRef::DumpTypeValue(
32023219
ReconstructType(type), s, format, data, data_offset, data_byte_size,
32033220
bitfield_bit_size, bitfield_bit_offset, exe_scope, is_base_class);
32043221
}
3222+
case Node::Kind::TypeAlias:
3223+
case Node::Kind::BoundGenericTypeAlias: {
3224+
// This means we have an unresolved type alias that even
3225+
// SwiftASTContext couldn't resolve. This happens for ObjC
3226+
// typedefs such as CFString in the REPL. More investigation is
3227+
// needed.
3228+
return m_swift_ast_context->DumpTypeValue(
3229+
ReconstructType(type), s, format, data, data_offset, data_byte_size,
3230+
bitfield_bit_size, bitfield_bit_offset, exe_scope, is_base_class);
3231+
}
32053232
default:
32063233
assert(false && "Unhandled node kind");
32073234
LLDB_LOGF(GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
@@ -3470,16 +3497,23 @@ TypeSystemSwiftTypeRef::GetGenericArgumentType(opaque_compiler_type_t type,
34703497
(ReconstructType(type), idx));
34713498
}
34723499
#ifndef NDEBUG
3473-
bool TypeSystemSwiftTypeRef::ShouldSkipValidation(opaque_compiler_type_t type) { \
3474-
// NSNotificationName is a typedef to a NSString in clang type, but it's a
3500+
bool TypeSystemSwiftTypeRef::ShouldSkipValidation(opaque_compiler_type_t type) {
3501+
auto mangled_name = GetMangledTypeName(type);
3502+
// NSNotificationName is a typedef to a NSString in clang type, but it's a
34753503
// struct in SwiftASTContext. Skip validation in this case.
3504+
if (mangled_name == "$sSo18NSNotificationNameaD")
3505+
return true;
3506+
34763507
// $s10Foundation12NotificationV4NameaD is a typealias to NSNotificationName,
34773508
// so we skip validation in that casse as well.
3478-
auto mangled_name = GetMangledTypeName(type);
3479-
if (mangled_name == "$sSo18NSNotificationNameaD" ||
3480-
mangled_name == "$s10Foundation12NotificationV4NameaD" ||
3481-
mangled_name == "$sSo9NSDecimalaD")
3482-
return true;
3509+
if (mangled_name == "$s10Foundation12NotificationV4NameaD")
3510+
return true;
3511+
if (mangled_name == "$sSo9NSDecimalaD")
3512+
return true;
3513+
// Reconstruct($sSo11CFStringRefaD) returns a non-typealias type, breaking
3514+
// isTypedef().
3515+
if (mangled_name == "$sSo11CFStringRefaD")
3516+
return true;
34833517

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

0 commit comments

Comments
 (0)