Author: Michael Buch
Date: 2026-01-20T18:26:23Z
New Revision: 3aea01b271ae5908e99cb4b12263ca450ab91afc

URL: 
https://github.com/llvm/llvm-project/commit/3aea01b271ae5908e99cb4b12263ca450ab91afc
DIFF: 
https://github.com/llvm/llvm-project/commit/3aea01b271ae5908e99cb4b12263ca450ab91afc.diff

LOG: [lldb][DWARFASTParserClang] RequireCompleteType for ObjC types (#176765)

Currently we forcefully complete C++ types if we can't find their
definition for layout purposes. This ensures that we at least don't
crash in Clang when laying out the type. The definition is required for
types of members/array elements/base classes for the purposes of
calculating their layout. This is also true for Obj-C types, but we
haven't been forcefully completing those.

The test-case that's being un-XFAILed in this patch demonstrates a case
where not completing the super-class forcefully causes a clang crash.

rdar://168440264

Added: 
    

Modified: 
    lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
    lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
    lldb/test/Shell/Expr/TestObjCIncompleteSuperclass.test

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index d7a7f44622c68..a9945aa14a506 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -1622,6 +1622,12 @@ void DWARFASTParserClang::ParseInheritance(
 
   CompilerType base_class_clang_type = base_class_type->GetFullCompilerType();
   assert(base_class_clang_type);
+
+  // Make sure all base classes refer to complete types and not forward
+  // declarations. If we don't do this, clang will crash with an
+  // assertion in the call to clang_type.TransferBaseClasses()
+  TypeSystemClang::RequireCompleteType(base_class_clang_type);
+
   if (TypeSystemClang::IsObjCObjectOrInterfaceType(class_clang_type)) {
     ast->SetObjCSuperClass(class_clang_type, base_class_clang_type);
     return;
@@ -2248,19 +2254,8 @@ bool DWARFASTParserClang::CompleteRecordType(const 
DWARFDIE &die,
     return {};
   }
 
-  if (!bases.empty()) {
-    // Make sure all base classes refer to complete types and not forward
-    // declarations. If we don't do this, clang will crash with an
-    // assertion in the call to clang_type.TransferBaseClasses()
-    for (const auto &base_class : bases) {
-      clang::TypeSourceInfo *type_source_info = 
base_class->getTypeSourceInfo();
-      if (type_source_info)
-        TypeSystemClang::RequireCompleteType(
-            m_ast.GetType(type_source_info->getType()));
-    }
-
+  if (!bases.empty())
     m_ast.TransferBaseClasses(clang_type.GetOpaqueQualType(), 
std::move(bases));
-  }
 
   m_ast.AddMethodOverridesForCXXRecordType(clang_type.GetOpaqueQualType());
   TypeSystemClang::BuildIndirectFields(clang_type);

diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index ee3f17e975d80..34d97a07d73fc 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -9702,7 +9702,8 @@ TypeSystemClang::DeclContextGetTypeSystemClang(const 
CompilerDeclContext &dc) {
 void TypeSystemClang::RequireCompleteType(CompilerType type) {
   // Technically, enums can be incomplete too, but we don't handle those as 
they
   // are emitted even under -flimit-debug-info.
-  if (!TypeSystemClang::IsCXXClassType(type))
+  if (!TypeSystemClang::IsCXXClassType(type) &&
+      !TypeSystemClang::IsObjCObjectOrInterfaceType(type))
     return;
 
   if (type.GetCompleteType())

diff  --git a/lldb/test/Shell/Expr/TestObjCIncompleteSuperclass.test 
b/lldb/test/Shell/Expr/TestObjCIncompleteSuperclass.test
index b6c27826c437e..22296f3e30a43 100644
--- a/lldb/test/Shell/Expr/TestObjCIncompleteSuperclass.test
+++ b/lldb/test/Shell/Expr/TestObjCIncompleteSuperclass.test
@@ -3,7 +3,6 @@
 # it will fail to do so. LLDB should handle this situation gracefully.
 # A super-class definition is required when laying out Obj-C types.
 #
-# XFAIL: *
 # REQUIRES: system-darwin
 #
 # RUN: split-file %s %t


        
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to