Skip to content

Commit c0eeea5

Browse files
committed
Register Objective-C property accessors with their property decls.
This is a correctness fix for the Clang DWARF parser that primarily matters for swift-lldb's ability to import Clang types that were reconstructed from DWARF into Swift. rdar://problem/55025799 Differential Revision: https://reviews.llvm.org/D70580
1 parent 01e8dd2 commit c0eeea5

File tree

5 files changed

+77
-32
lines changed

5 files changed

+77
-32
lines changed

lldb/source/Symbol/ClangASTContext.cpp

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8435,9 +8435,11 @@ bool ClangASTContext::AddObjCClassProperty(
84358435
const bool isInstance =
84368436
(property_attributes & ObjCPropertyDecl::OBJC_PR_class) == 0;
84378437

8438-
if (!getter_sel.isNull() &&
8439-
!(isInstance ? class_interface_decl->lookupInstanceMethod(getter_sel)
8440-
: class_interface_decl->lookupClassMethod(getter_sel))) {
8438+
clang::ObjCMethodDecl *getter = nullptr;
8439+
if (!getter_sel.isNull())
8440+
getter = isInstance ? class_interface_decl->lookupInstanceMethod(getter_sel)
8441+
: class_interface_decl->lookupClassMethod(getter_sel);
8442+
if (!getter_sel.isNull() && !getter) {
84418443
const bool isVariadic = false;
84428444
const bool isPropertyAccessor = false;
84438445
const bool isSynthesizedAccessorStub = false;
@@ -8447,28 +8449,31 @@ bool ClangASTContext::AddObjCClassProperty(
84478449
clang::ObjCMethodDecl::None;
84488450
const bool HasRelatedResultType = false;
84498451

8450-
clang::ObjCMethodDecl *getter = clang::ObjCMethodDecl::Create(
8452+
getter = clang::ObjCMethodDecl::Create(
84518453
*clang_ast, clang::SourceLocation(), clang::SourceLocation(),
84528454
getter_sel, ClangUtil::GetQualType(property_clang_type_to_access),
84538455
nullptr, class_interface_decl, isInstance, isVariadic,
84548456
isPropertyAccessor, isSynthesizedAccessorStub, isImplicitlyDeclared,
84558457
isDefined, impControl, HasRelatedResultType);
84568458

8457-
if (getter && metadata)
8458-
ClangASTContext::SetMetadata(clang_ast, getter, *metadata);
8459-
84608459
if (getter) {
8461-
getter->setMethodParams(*clang_ast,
8460+
if (metadata)
8461+
ClangASTContext::SetMetadata(clang_ast, getter, *metadata);
8462+
getter->setMethodParams(*clang_ast,
84628463
llvm::ArrayRef<clang::ParmVarDecl *>(),
84638464
llvm::ArrayRef<clang::SourceLocation>());
8464-
84658465
class_interface_decl->addDecl(getter);
84668466
}
84678467
}
8468+
if (getter) {
8469+
getter->setPropertyAccessor(true);
8470+
property_decl->setGetterMethodDecl(getter);
8471+
}
84688472

8469-
if (!setter_sel.isNull() &&
8470-
!(isInstance ? class_interface_decl->lookupInstanceMethod(setter_sel)
8471-
: class_interface_decl->lookupClassMethod(setter_sel))) {
8473+
clang::ObjCMethodDecl *setter = nullptr;
8474+
setter = isInstance ? class_interface_decl->lookupInstanceMethod(setter_sel)
8475+
: class_interface_decl->lookupClassMethod(setter_sel);
8476+
if (!setter_sel.isNull() && !setter) {
84728477
clang::QualType result_type = clang_ast->VoidTy;
84738478
const bool isVariadic = false;
84748479
const bool isPropertyAccessor = true;
@@ -8479,31 +8484,35 @@ bool ClangASTContext::AddObjCClassProperty(
84798484
clang::ObjCMethodDecl::None;
84808485
const bool HasRelatedResultType = false;
84818486

8482-
clang::ObjCMethodDecl *setter = clang::ObjCMethodDecl::Create(
8487+
setter = clang::ObjCMethodDecl::Create(
84838488
*clang_ast, clang::SourceLocation(), clang::SourceLocation(),
84848489
setter_sel, result_type, nullptr, class_interface_decl, isInstance,
84858490
isVariadic, isPropertyAccessor, isSynthesizedAccessorStub,
84868491
isImplicitlyDeclared, isDefined, impControl, HasRelatedResultType);
84878492

8488-
if (setter && metadata)
8489-
ClangASTContext::SetMetadata(clang_ast, setter, *metadata);
8493+
if (setter) {
8494+
if (metadata)
8495+
ClangASTContext::SetMetadata(clang_ast, setter, *metadata);
84908496

8491-
llvm::SmallVector<clang::ParmVarDecl *, 1> params;
8497+
llvm::SmallVector<clang::ParmVarDecl *, 1> params;
84928498

8493-
params.push_back(clang::ParmVarDecl::Create(
8494-
*clang_ast, setter, clang::SourceLocation(), clang::SourceLocation(),
8495-
nullptr, // anonymous
8496-
ClangUtil::GetQualType(property_clang_type_to_access), nullptr,
8497-
clang::SC_Auto, nullptr));
8499+
params.push_back(clang::ParmVarDecl::Create(
8500+
*clang_ast, setter, clang::SourceLocation(), clang::SourceLocation(),
8501+
nullptr, // anonymous
8502+
ClangUtil::GetQualType(property_clang_type_to_access), nullptr,
8503+
clang::SC_Auto, nullptr));
84988504

8499-
if (setter) {
85008505
setter->setMethodParams(*clang_ast,
85018506
llvm::ArrayRef<clang::ParmVarDecl *>(params),
85028507
llvm::ArrayRef<clang::SourceLocation>());
85038508

85048509
class_interface_decl->addDecl(setter);
85058510
}
85068511
}
8512+
if (setter) {
8513+
setter->setPropertyAccessor(true);
8514+
property_decl->setSetterMethodDecl(setter);
8515+
}
85078516

85088517
return true;
85098518
}
@@ -8939,16 +8948,23 @@ void ClangASTContext::DumpFromSymbolFile(Stream &s,
89398948

89408949
s << type->GetName().AsCString() << "\n";
89418950

8942-
if (clang::TagDecl *tag_decl =
8943-
GetAsTagDecl(type->GetFullCompilerType()))
8951+
CompilerType full_type = type->GetFullCompilerType();
8952+
if (clang::TagDecl *tag_decl = GetAsTagDecl(full_type)) {
89448953
tag_decl->dump(s.AsRawOstream());
8945-
else if (clang::TypedefNameDecl *typedef_decl =
8946-
GetAsTypedefDecl(type->GetFullCompilerType()))
8954+
continue;
8955+
}
8956+
if (clang::TypedefNameDecl *typedef_decl = GetAsTypedefDecl(full_type)) {
89478957
typedef_decl->dump(s.AsRawOstream());
8948-
else {
8949-
GetCanonicalQualType(type->GetFullCompilerType().GetOpaqueQualType())
8950-
.dump(s.AsRawOstream());
8958+
continue;
8959+
}
8960+
if (auto *objc_obj = llvm::dyn_cast<clang::ObjCObjectType>(
8961+
ClangUtil::GetQualType(full_type).getTypePtr())) {
8962+
if (clang::ObjCInterfaceDecl *interface_decl = objc_obj->getInterface()) {
8963+
interface_decl->dump(s.AsRawOstream());
8964+
continue;
8965+
}
89518966
}
8967+
GetCanonicalQualType(full_type.GetOpaqueQualType()).dump(s.AsRawOstream());
89528968
}
89538969
}
89548970

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// REQUIRES: system-darwin
2+
//
3+
// RUN: %clang_host -g -c -o %t.o %s
4+
// RUN: lldb-test symbols -dump-clang-ast %t.o | FileCheck %s
5+
6+
__attribute__((objc_root_class))
7+
@interface Root
8+
@property (readonly) int ro_number;
9+
@property int rw_number;
10+
@property (readonly, getter=custom_getter) int manual;
11+
- (int)custom_getter;
12+
@property (class, readonly) int class_property;
13+
@end
14+
15+
Root *obj;
16+
17+
// CHECK: |-ObjCPropertyDecl {{.*}} ro_number 'int' readonly
18+
// CHECK: | `-getter ObjCMethod [[READONLY:0x[0-9a-f]+]] 'ro_number'
19+
// CHECK: |-ObjCMethodDecl [[READONLY]] {{.*}} implicit - ro_number 'int'
20+
// CHECK: |-ObjCPropertyDecl {{.*}} rw_number 'int' assign readwrite
21+
// CHECK: | |-getter ObjCMethod {{.*}} 'rw_number'
22+
// CHECK: | `-setter ObjCMethod {{.*}} 'setRw_number:'
23+
// CHECK: |-ObjCPropertyDecl {{.*}} manual 'int' readonly
24+
// CHECK: | `-getter ObjCMethod [[CUSTOM:0x[0-9a-f]+]] 'custom_getter'
25+
// CHECK: |-ObjCMethodDecl [[CUSTOM]] {{.*}} - custom_getter 'int'
26+
// CHECK: |-ObjCPropertyDecl {{.*}} class_property 'int' readonly class
27+
// CHECK: | `-getter ObjCMethod [[CLASS:0x[0-9a-f]+]] 'class_property'
28+
// CHECK: `-ObjCMethodDecl [[CLASS]] {{.*}} + class_property 'int'
29+

lldb/test/Shell/SymbolFile/DWARF/clang-ast-from-dwarf-unamed-and-anon-structs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// UNSUPPORTED: system-windows
22
//
3-
// Test to verify we are corectly generating anonymous flags when parsing
3+
// Test to verify we are correctly generating anonymous flags when parsing
44
// anonymous class and unnamed structs from DWARF to the a clang AST node.
55

66
// RUN: %clangxx_host -g -c -o %t.o %s
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
config.suffixes = ['.cpp', '.s', '.test', '.ll']
1+
config.suffixes = ['.cpp', '.m', '.s', '.test', '.ll']

lldb/tools/lldb-test/lldb-test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ Error opts::symbols::dumpClangAST(lldb_private::Module &Module) {
623623
return make_string_error("Module has no symbol file.");
624624

625625
llvm::Expected<TypeSystem &> type_system_or_err =
626-
symfile->GetTypeSystemForLanguage(eLanguageTypeC_plus_plus);
626+
symfile->GetTypeSystemForLanguage(eLanguageTypeObjC_plus_plus);
627627
if (!type_system_or_err)
628628
return make_string_error("Can't retrieve ClangASTContext");
629629

0 commit comments

Comments
 (0)