https://github.com/Michael137 created 
https://github.com/llvm/llvm-project/pull/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

>From ec3b057094e51cdf24786d0ea12dea0b53cf35f4 Mon Sep 17 00:00:00 2001
From: Michael Buch <[email protected]>
Date: Mon, 19 Jan 2026 15:21:21 +0000
Subject: [PATCH] [lldb][DWARFASTParserClang] RequireCompleteType for ObjC
 types

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
---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 19 +++++++------------
 .../TypeSystem/Clang/TypeSystemClang.cpp      |  3 ++-
 .../Expr/TestObjCIncompleteSuperclass.test    |  1 -
 3 files changed, 9 insertions(+), 14 deletions(-)

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