[Lldb-commits] [lldb] ef423a3 - Add Objective-C property accessors loaded from Clang module DWARF to lookup
Adrian Prantl via lldb-commits
lldb-commits at lists.llvm.org
Fri Apr 24 11:11:09 PDT 2020
Author: Adrian Prantl
Date: 2020-04-24T11:10:50-07:00
New Revision: ef423a3ba57045f80b0fcafce72121449a8b54d4
URL: https://github.com/llvm/llvm-project/commit/ef423a3ba57045f80b0fcafce72121449a8b54d4
DIFF: https://github.com/llvm/llvm-project/commit/ef423a3ba57045f80b0fcafce72121449a8b54d4.diff
LOG: Add Objective-C property accessors loaded from Clang module DWARF to lookup
This patch fixes a bug when synthesizing an ObjC property from
-gmodules debug info. Because the method declaration that is injected
via the non-modular property implementation is not added to the
ObjCInterfaceDecl's lookup pointer, a second copy of the accessor
would be generated when processing the ObjCPropertyDecl. This can be
avoided by finding the existing method decl in
ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName() and
adding it to the LookupPtr.
Differential Revision: https://reviews.llvm.org/D78333
Added:
Modified:
lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
lldb/test/Shell/SymbolFile/DWARF/module-ownership.mm
Removed:
################################################################################
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp
index 943058fde5ad..e4054b441d55 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp
@@ -10,6 +10,7 @@
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
#include "clang/AST/Decl.h"
+#include "clang/AST/DeclObjC.h"
using namespace lldb_private;
@@ -46,6 +47,19 @@ void ClangExternalASTSourceCallbacks::FindExternalLexicalDecls(
}
}
+bool ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName(
+ const clang::DeclContext *DC, clang::DeclarationName Name) {
+ llvm::SmallVector<clang::NamedDecl *, 4> decls;
+ // Objective-C methods are not added into the LookupPtr when they originate
+ // from an external source. SetExternalVisibleDeclsForName() adds them.
+ if (auto *oid = llvm::dyn_cast<clang::ObjCInterfaceDecl>(DC)) {
+ for (auto *omd : oid->methods())
+ if (omd->getDeclName() == Name)
+ decls.push_back(omd);
+ }
+ return !SetExternalVisibleDeclsForName(DC, Name, decls).empty();
+}
+
OptionalClangModuleID
ClangExternalASTSourceCallbacks::RegisterModule(clang::Module *module) {
m_modules.push_back(module);
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h
index fc6ba0d3327c..69088d9c82a5 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h
@@ -30,6 +30,9 @@ class ClangExternalASTSourceCallbacks : public clang::ExternalASTSource {
llvm::function_ref<bool(clang::Decl::Kind)> IsKindWeWant,
llvm::SmallVectorImpl<clang::Decl *> &Result) override;
+ bool FindExternalVisibleDeclsByName(const clang::DeclContext *DC,
+ clang::DeclarationName Name) override;
+
void CompleteType(clang::TagDecl *tag_decl) override;
void CompleteType(clang::ObjCInterfaceDecl *objc_decl) override;
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 20b06c6e62d2..3446db0b1214 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -344,6 +344,13 @@ static void SetMemberOwningModule(clang::Decl *member,
member->setFromASTFile();
member->setOwningModuleID(id.GetValue());
member->setModuleOwnershipKind(clang::Decl::ModuleOwnershipKind::Visible);
+ if (auto *nd = llvm::dyn_cast<clang::NamedDecl>(member))
+ if (auto *dc = llvm::dyn_cast<clang::DeclContext>(parent)) {
+ dc->setHasExternalVisibleStorage(true);
+ // This triggers ExternalASTSource::FindExternalVisibleDeclsByName() to be
+ // called when searching for members.
+ dc->setHasExternalLexicalStorage(true);
+ }
}
char TypeSystemClang::ID;
diff --git a/lldb/test/Shell/SymbolFile/DWARF/module-ownership.mm b/lldb/test/Shell/SymbolFile/DWARF/module-ownership.mm
index 5fccc44c34ef..f6522e1a808c 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/module-ownership.mm
+++ b/lldb/test/Shell/SymbolFile/DWARF/module-ownership.mm
@@ -33,14 +33,21 @@
// CHECK-DAG: EnumDecl {{.*}} imported in A {{.*}} Enum_e
// FIXME: -EnumConstantDecl {{.*}} imported in A a
+ at implementation SomeClass {
+ int private_ivar;
+}
+ at synthesize number = private_ivar;
+ at end
+
SomeClass *obj1;
// RUN: lldb-test symbols -dump-clang-ast -find type --language=ObjC++ \
// RUN: -compiler-context 'Module:A,Struct:SomeClass' %t.o \
// RUN: | FileCheck %s --check-prefix=CHECK-OBJC
// CHECK-OBJC: ObjCInterfaceDecl {{.*}} imported in A SomeClass
-// CHECK-OBJC: |-ObjCPropertyDecl {{.*}} imported in A number 'int' readonly
-// CHECK-OBJC: | `-getter ObjCMethod {{.*}} 'number'
-// CHECK-OBJC: `-ObjCMethodDecl {{.*}} imported in A implicit - number 'int'
+// CHECK-OBJC-NEXT: |-ObjCIvarDecl
+// CHECK-OBJC-NEXT: |-ObjCMethodDecl 0x[[NUMBER:[0-9a-f]+]]{{.*}} imported in A
+// CHECK-OBJC-NEXT: `-ObjCPropertyDecl {{.*}} imported in A number 'int' readonly
+// CHECK-OBJC-NEXT: `-getter ObjCMethod 0x[[NUMBER]] 'number'
// Template specializations are not yet supported, so they lack the ownership info:
Template<int> t2;
More information about the lldb-commits
mailing list