From fe8e25a48a2a0f8f508499ba950181dba3d600b0 Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Mon, 30 Dec 2019 21:20:01 +0100 Subject: [lldb][NFC] Create type-safe function for creating a CompilerType from a QualType LLDB frequently converts QualType to CompilerType. This is currently done like this: result = CompilerType(this, qual_type_var.getAsOpaquePtr()) There are a few shortcomings in this current approach: 1. CompilerType's constructor takes a void* pointer so it isn't type safe. 2. We can't add any sanity checks to the CompilerType constructor (e.g. that the type actually belongs to the passed ClangASTContext) without expanding the TypeSystem API. 3. The logic for converting QualType->CompilerType is spread out over all of LLDB so changing it is difficult (e.g., what if we want to just pass the type ptr and not the 1type_ptr | qual_flags1 to CompilerType). This patch adds a `ClangASTContext::GetType` function similar to the other GetTypeForDecl functions that does this conversion in a type safe way. It also adds a sanity check for Tag-based types that the type actually belongs to the current ClangASTContext (Types don't seem to know their ASTContext, so we have to workaround by looking at the decl for the underlying TagDecl. This doesn't cover all types we construct but it's better than no sanity check). --- lldb/source/Plugins/Language/ObjC/NSArray.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lldb/source/Plugins/Language/ObjC/NSArray.cpp') diff --git a/lldb/source/Plugins/Language/ObjC/NSArray.cpp b/lldb/source/Plugins/Language/ObjC/NSArray.cpp index 64461fc2bc0..0ac7fb6d233 100644 --- a/lldb/source/Plugins/Language/ObjC/NSArray.cpp +++ b/lldb/source/Plugins/Language/ObjC/NSArray.cpp @@ -612,9 +612,8 @@ lldb_private::formatters::GenericNSArrayISyntheticFrontEnd:: auto *clang_ast_context = ClangASTContext::GetScratch( *valobj_sp->GetExecutionContextRef().GetTargetSP()); if (clang_ast_context) - m_id_type = CompilerType(clang_ast_context, - clang_ast_context->getASTContext() - .ObjCBuiltinIdTy.getAsOpaquePtr()); + m_id_type = clang_ast_context->GetType( + clang_ast_context->getASTContext().ObjCBuiltinIdTy); } } } -- cgit v1.2.3