[llvm-branch-commits] [lldb] 839e845 - [lldb] Remove assumption from Clang-based data formatters that their types are in the scratch AST
Raphael Isemann via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Dec 10 08:39:13 PST 2020
Author: Raphael Isemann
Date: 2020-12-10T17:35:03+01:00
New Revision: 839e845277894ad37fbca8063cbf1955331fbeff
URL: https://github.com/llvm/llvm-project/commit/839e845277894ad37fbca8063cbf1955331fbeff
DIFF: https://github.com/llvm/llvm-project/commit/839e845277894ad37fbca8063cbf1955331fbeff.diff
LOG: [lldb] Remove assumption from Clang-based data formatters that their types are in the scratch AST
Several data formatters assume their types are in the Target's scratch AST and
build new types from that scratch AST instance. However, types from different
ASTs shouldn't be mixed, so this (unchecked) assumption may lead to problems if
we ever have more than one scratch AST or someone somehow invokes data
formatters on a type that are not in the scratch AST.
Instead we can use in all the formatters just the TypeSystem of the type we're
formatting. That's much simpler and avoids all the headache of finding the right
TypeSystem that matches the one of the formatted type.
Right now LLDB only has one scratch TypeSystemClang instance and we format only
types that are in the scratch AST, so this doesn't change anything in the
current way LLDB works. The intention here is to allow follow up refactorings
that introduce multiple scratch ASTs with the same Target.
Differential Revision: https://reviews.llvm.org/D92757
Added:
Modified:
lldb/source/DataFormatters/VectorType.cpp
lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
lldb/source/Plugins/Language/ObjC/CoreMedia.cpp
Removed:
################################################################################
diff --git a/lldb/source/DataFormatters/VectorType.cpp b/lldb/source/DataFormatters/VectorType.cpp
index fd1c0bc96cd4..cc24bb1de428 100644
--- a/lldb/source/DataFormatters/VectorType.cpp
+++ b/lldb/source/DataFormatters/VectorType.cpp
@@ -220,20 +220,8 @@ class VectorTypeSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
CompilerType parent_type(m_backend.GetCompilerType());
CompilerType element_type;
parent_type.IsVectorType(&element_type, nullptr);
- TypeSystem *type_system = nullptr;
- if (auto target_sp = m_backend.GetTargetSP()) {
- auto type_system_or_err =
- target_sp->GetScratchTypeSystemForLanguage(lldb::eLanguageTypeC);
- if (auto err = type_system_or_err.takeError()) {
- LLDB_LOG_ERROR(
- lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS),
- std::move(err), "Unable to update from scratch TypeSystem");
- } else {
- type_system = &type_system_or_err.get();
- }
- }
- m_child_type =
- ::GetCompilerTypeForFormat(m_parent_format, element_type, type_system);
+ m_child_type = ::GetCompilerTypeForFormat(m_parent_format, element_type,
+ parent_type.GetTypeSystem());
m_num_children = ::CalculateNumChildren(parent_type, m_child_type);
m_item_format = GetItemFormatForFormat(m_parent_format, m_child_type);
return false;
diff --git a/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp b/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
index 42f6bd9ffb7b..35788a6445c2 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
@@ -50,11 +50,7 @@ class BlockPointerSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
}
TypeSystemClang *clang_ast_context =
- llvm::dyn_cast<TypeSystemClang>(&type_system_or_err.get());
-
- if (!clang_ast_context) {
- return;
- }
+ llvm::cast<TypeSystemClang>(block_pointer_type.GetTypeSystem());
std::shared_ptr<ClangASTImporter> clang_ast_importer;
auto *state = target_sp->GetPersistentExpressionStateForLanguage(
diff --git a/lldb/source/Plugins/Language/ObjC/CoreMedia.cpp b/lldb/source/Plugins/Language/ObjC/CoreMedia.cpp
index ac2f45b8354f..efc80cc75557 100644
--- a/lldb/source/Plugins/Language/ObjC/CoreMedia.cpp
+++ b/lldb/source/Plugins/Language/ObjC/CoreMedia.cpp
@@ -25,21 +25,12 @@ bool lldb_private::formatters::CMTimeSummaryProvider(
if (!type.IsValid())
return false;
- auto type_system_or_err =
- valobj.GetExecutionContextRef()
- .GetTargetSP()
- ->GetScratchTypeSystemForLanguage(lldb::eLanguageTypeC);
- if (auto err = type_system_or_err.takeError()) {
- LLDB_LOG_ERROR(
- lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS),
- std::move(err), "Failed to get scratch type system");
- return false;
- }
+ TypeSystem *type_system = type.GetTypeSystem();
// fetch children by offset to compensate for potential lack of debug info
- auto int64_ty = type_system_or_err->GetBuiltinTypeForEncodingAndBitSize(
- eEncodingSint, 64);
- auto int32_ty = type_system_or_err->GetBuiltinTypeForEncodingAndBitSize(
- eEncodingSint, 32);
+ auto int64_ty =
+ type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, 64);
+ auto int32_ty =
+ type_system->GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, 32);
auto value_sp(valobj.GetSyntheticChildAtOffset(0, int64_ty, true));
auto timescale_sp(valobj.GetSyntheticChildAtOffset(8, int32_ty, true));
More information about the llvm-branch-commits
mailing list