Skip to content

[lldb] Skip validation of simd types on typedef functions in tsstyperef #3337

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
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
41 changes: 41 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "lldb/Symbol/TypeList.h"
#include "lldb/Symbol/TypeMap.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/RegularExpression.h"
#include "lldb/Utility/Timer.h"

#include "Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h"
Expand Down Expand Up @@ -3288,6 +3289,36 @@ TypeSystemSwiftTypeRef::GetTypeBitAlign(opaque_compiler_type_t type,
return {};
}

#ifndef NDEBUG
static bool IsSIMDNode(NodePointer node) {
// A SIMD vector is a clang typealias whose identifier starts with "simd_".
if (node->getKind() == Node::Kind::TypeAlias && node->getNumChildren() >= 2) {
NodePointer module = node->getFirstChild();
NodePointer identifier = node->getChild(1);
return module->getKind() == Node::Kind::Module &&
module->getText() == "__C" &&
identifier->getKind() == Node::Kind::Identifier &&
identifier->getText().startswith("simd_");
}
// A SIMD matrix is a BoundGenericStructure whose inner identifier starts with
// SIMD.
if (node->getKind() == Node::Kind::BoundGenericStructure &&
node->hasChildren()) {
NodePointer type = node->getFirstChild();
if (type->getKind() == Node::Kind::Type && node->hasChildren()) {
NodePointer structure = type->getFirstChild();
if (structure->getKind() == Node::Kind::Structure &&
structure->getNumChildren() >= 2) {
NodePointer identifier = structure->getChild(1);
return identifier->getKind() == Node::Kind::Identifier &&
identifier->getText().startswith("SIMD");
}
}
}
return false;
}
#endif

bool TypeSystemSwiftTypeRef::IsTypedefType(opaque_compiler_type_t type) {
auto impl = [&]() {
using namespace swift::Demangle;
Expand Down Expand Up @@ -3317,6 +3348,11 @@ bool TypeSystemSwiftTypeRef::IsTypedefType(opaque_compiler_type_t type) {
if (mangled_name == "$sSo18NSNotificationNameaD" ||
mangled_name == "$sSo9NSDecimalaD")
return impl();

// SIMD types have some special handling in the compiler, causing divergences
// on the way SwiftASTContext and TypeSystemSwiftTypeRef view the same type.
if (IsSIMDNode(node))
return impl();
#endif
VALIDATE_AND_RETURN(impl, IsTypedefType, type, (ReconstructType(type)),
(ReconstructType(type)));
Expand Down Expand Up @@ -3363,6 +3399,11 @@ TypeSystemSwiftTypeRef::GetTypedefedType(opaque_compiler_type_t type) {
if (mangled_name == "$sSo18NSNotificationNameaD" ||
mangled_name == "$sSo9NSDecimalaD")
return impl();

// SIMD types have some special handling in the compiler, causing divergences
// on the way SwiftASTContext and TypeSystemSwiftTypeRef view the same type.
if (IsSIMDNode(node))
return impl();
#endif
VALIDATE_AND_RETURN(impl, GetTypedefedType, type, (ReconstructType(type)),
(ReconstructType(type)));
Expand Down