Skip to content

Commit 18c955b

Browse files
authored
Merge pull request #8891 from Michael137/lldb/crash/get-complete-objc-type-to-next
[lldb][Type Completion] Fix completion of ObjCObjectTypes #8891 The problem was introduced in: ``` commit e68f76a9e59104e2bfb972155af8ff04310cd078 Author: Michael Buch <[email protected]> Date: Fri Feb 16 14:35:34 2024 +0000 [lldb][TypeSystemClang][NFCI] Factor completion logic out of GetCompleteQualType ``` This introduced an incorrect `llvm::dyn_cast_or_null` check causing us to incorrectly claim that we failed to complete a type. This manifested in a crash when running following expression: ``` expr -l objc -- *(id)0x1234 ``` rdar://129633122
2 parents c2ecff5 + e3fc073 commit 18c955b

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2752,13 +2752,9 @@ static clang::Type const *GetCompleteEnumType(clang::ASTContext *ast,
27522752
}
27532753

27542754
static clang::Type const *
2755-
GetCompleteObjCInterfaceType(clang::ASTContext *ast, clang::QualType qual_type,
2755+
GetCompleteObjCInterfaceType(clang::ASTContext *ast,
2756+
clang::ObjCObjectType const *objc_class_type,
27562757
bool allow_completion = true) {
2757-
const clang::ObjCObjectType *objc_class_type =
2758-
llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
2759-
if (!objc_class_type)
2760-
return nullptr;
2761-
27622758
clang::ObjCInterfaceDecl *class_interface_decl =
27632759
objc_class_type->getInterface();
27642760
// We currently can't complete objective C types through the newly added
@@ -2819,8 +2815,13 @@ static bool GetCompleteQualType(clang::ASTContext *ast,
28192815
} break;
28202816
case clang::Type::ObjCObject:
28212817
case clang::Type::ObjCInterface: {
2822-
if (auto const *ty = llvm::dyn_cast_or_null<ObjCInterfaceType>(
2823-
GetCompleteObjCInterfaceType(ast, qual_type, allow_completion)))
2818+
const clang::ObjCObjectType *objc_class_type =
2819+
llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
2820+
if (!objc_class_type)
2821+
return true;
2822+
2823+
if (auto const *ty = GetCompleteObjCInterfaceType(ast, objc_class_type,
2824+
allow_completion))
28242825
return TypeSystemClang::UseRedeclCompletion() || !ty->isIncompleteType();
28252826

28262827
return false;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int main() { return 0; }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// UNSUPPORTED: system-linux, system-windows
2+
//
3+
// RUN: %clangxx_host %p/Inputs/objc-cast.cpp -g -o %t
4+
// RUN: %lldb %t \
5+
// RUN: -o "b main" -o run -o "expression --language objc -- *(id)0x1" \
6+
// RUN: -b 2>&1 | FileCheck %s
7+
8+
// CHECK: (lldb) expression --language objc -- *(id)0x1
9+
// CHECK: error: Couldn't apply expression side effects : Couldn't dematerialize a result variable: couldn't read its memory

0 commit comments

Comments
 (0)