aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/lldb/source/Plugins/TypeSystem
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2022-01-27 22:17:16 +0000
committerDimitry Andric <dim@FreeBSD.org>2022-06-04 11:59:19 +0000
commit390adc38fc112be360bd15499e5241bf4e675b6f (patch)
tree712d68d3aa03f7aa4902ba03dcac2a56f49ae0e5 /contrib/llvm-project/lldb/source/Plugins/TypeSystem
parent8a84287b0edc66fc6dede3db770d10ff41da5464 (diff)
downloadsrc-390adc38fc112be360bd15499e5241bf4e675b6f.tar.gz
src-390adc38fc112be360bd15499e5241bf4e675b6f.zip
Merge llvm-project main llvmorg-14-init-17616-g024a1fab5c35
This updates llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp to llvmorg-14-init-17616-g024a1fab5c35. PR: 261742 MFC after: 2 weeks (cherry picked from commit 04eeddc0aa8e0a417a16eaf9d7d095207f4a8623)
Diffstat (limited to 'contrib/llvm-project/lldb/source/Plugins/TypeSystem')
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp71
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h11
2 files changed, 74 insertions, 8 deletions
diff --git a/contrib/llvm-project/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/contrib/llvm-project/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 57e763176ba0..c71a0120efde 100644
--- a/contrib/llvm-project/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/contrib/llvm-project/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -1345,7 +1345,30 @@ namespace {
bool IsValueParam(const clang::TemplateArgument &argument) {
return argument.getKind() == TemplateArgument::Integral;
}
+
+void AddAccessSpecifierDecl(clang::CXXRecordDecl *cxx_record_decl,
+ ASTContext &ct,
+ clang::AccessSpecifier previous_access,
+ clang::AccessSpecifier access_specifier) {
+ if (!cxx_record_decl->isClass() && !cxx_record_decl->isStruct())
+ return;
+ if (previous_access != access_specifier) {
+ // For struct, don't add AS_public if it's the first AccessSpecDecl.
+ // For class, don't add AS_private if it's the first AccessSpecDecl.
+ if ((cxx_record_decl->isStruct() &&
+ previous_access == clang::AccessSpecifier::AS_none &&
+ access_specifier == clang::AccessSpecifier::AS_public) ||
+ (cxx_record_decl->isClass() &&
+ previous_access == clang::AccessSpecifier::AS_none &&
+ access_specifier == clang::AccessSpecifier::AS_private)) {
+ return;
+ }
+ cxx_record_decl->addDecl(
+ AccessSpecDecl::Create(ct, access_specifier, cxx_record_decl,
+ SourceLocation(), SourceLocation()));
+ }
}
+} // namespace
static TemplateParameterList *CreateTemplateParameterList(
ASTContext &ast,
@@ -1453,7 +1476,7 @@ void TypeSystemClang::CreateFunctionTemplateSpecializationInfo(
/// as `int I = 3`.
static bool TemplateParameterAllowsValue(NamedDecl *param,
const TemplateArgument &value) {
- if (auto *type_param = llvm::dyn_cast<TemplateTypeParmDecl>(param)) {
+ if (llvm::isa<TemplateTypeParmDecl>(param)) {
// Compare the argument kind, i.e. ensure that <typename> != <int>.
if (value.getKind() != TemplateArgument::Type)
return false;
@@ -2552,6 +2575,22 @@ ClangASTMetadata *TypeSystemClang::GetMetadata(const clang::Type *object) {
return nullptr;
}
+void TypeSystemClang::SetCXXRecordDeclAccess(const clang::CXXRecordDecl *object,
+ clang::AccessSpecifier access) {
+ if (access == clang::AccessSpecifier::AS_none)
+ m_cxx_record_decl_access.erase(object);
+ else
+ m_cxx_record_decl_access[object] = access;
+}
+
+clang::AccessSpecifier
+TypeSystemClang::GetCXXRecordDeclAccess(const clang::CXXRecordDecl *object) {
+ auto It = m_cxx_record_decl_access.find(object);
+ if (It != m_cxx_record_decl_access.end())
+ return It->second;
+ return clang::AccessSpecifier::AS_none;
+}
+
clang::DeclContext *
TypeSystemClang::GetDeclContextForType(const CompilerType &type) {
return GetDeclContextForType(ClangUtil::GetQualType(type));
@@ -7276,9 +7315,17 @@ clang::FieldDecl *TypeSystemClang::AddFieldToRecordType(
}
if (field) {
- field->setAccess(
- TypeSystemClang::ConvertAccessTypeToAccessSpecifier(access));
-
+ clang::AccessSpecifier access_specifier =
+ TypeSystemClang::ConvertAccessTypeToAccessSpecifier(access);
+ field->setAccess(access_specifier);
+
+ if (clang::CXXRecordDecl *cxx_record_decl =
+ llvm::dyn_cast<CXXRecordDecl>(record_decl)) {
+ AddAccessSpecifierDecl(cxx_record_decl, ast->getASTContext(),
+ ast->GetCXXRecordDeclAccess(cxx_record_decl),
+ access_specifier);
+ ast->SetCXXRecordDeclAccess(cxx_record_decl, access_specifier);
+ }
record_decl->addDecl(field);
VerifyDecl(field);
@@ -7657,6 +7704,11 @@ clang::CXXMethodDecl *TypeSystemClang::AddMethodToCXXRecordType(
cxx_method_decl->setParams(llvm::ArrayRef<clang::ParmVarDecl *>(params));
+ AddAccessSpecifierDecl(cxx_record_decl, getASTContext(),
+ GetCXXRecordDeclAccess(cxx_record_decl),
+ access_specifier);
+ SetCXXRecordDeclAccess(cxx_record_decl, access_specifier);
+
cxx_record_decl->addDecl(cxx_method_decl);
// Sometimes the debug info will mention a constructor (default/copy/move),
@@ -8190,6 +8242,11 @@ bool TypeSystemClang::CompleteTagDeclarationDefinition(
if (qual_type.isNull())
return false;
+ TypeSystemClang *lldb_ast =
+ llvm::dyn_cast<TypeSystemClang>(type.GetTypeSystem());
+ if (lldb_ast == nullptr)
+ return false;
+
// Make sure we use the same methodology as
// TypeSystemClang::StartTagDeclarationDefinition() as to how we start/end
// the definition.
@@ -8220,6 +8277,8 @@ bool TypeSystemClang::CompleteTagDeclarationDefinition(
cxx_record_decl->setHasLoadedFieldsFromExternalStorage(true);
cxx_record_decl->setHasExternalLexicalStorage(false);
cxx_record_decl->setHasExternalVisibleStorage(false);
+ lldb_ast->SetCXXRecordDeclAccess(cxx_record_decl,
+ clang::AccessSpecifier::AS_none);
return true;
}
}
@@ -8233,10 +8292,6 @@ bool TypeSystemClang::CompleteTagDeclarationDefinition(
if (enum_decl->isCompleteDefinition())
return true;
- TypeSystemClang *lldb_ast =
- llvm::dyn_cast<TypeSystemClang>(type.GetTypeSystem());
- if (lldb_ast == nullptr)
- return false;
clang::ASTContext &ast = lldb_ast->getASTContext();
/// TODO This really needs to be fixed.
diff --git a/contrib/llvm-project/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/contrib/llvm-project/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
index 5e75a8aba9e8..c59ecdb31790 100644
--- a/contrib/llvm-project/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ b/contrib/llvm-project/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -196,6 +196,11 @@ public:
ClangASTMetadata *GetMetadata(const clang::Decl *object);
ClangASTMetadata *GetMetadata(const clang::Type *object);
+ void SetCXXRecordDeclAccess(const clang::CXXRecordDecl *object,
+ clang::AccessSpecifier access);
+ clang::AccessSpecifier
+ GetCXXRecordDeclAccess(const clang::CXXRecordDecl *object);
+
// Basic Types
CompilerType GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding,
size_t bit_size) override;
@@ -1084,6 +1089,12 @@ private:
/// Maps Types to their associated ClangASTMetadata.
TypeMetadataMap m_type_metadata;
+ typedef llvm::DenseMap<const clang::CXXRecordDecl *, clang::AccessSpecifier>
+ CXXRecordDeclAccessMap;
+ /// Maps CXXRecordDecl to their most recent added method/field's
+ /// AccessSpecifier.
+ CXXRecordDeclAccessMap m_cxx_record_decl_access;
+
/// The sema associated that is currently used to build this ASTContext.
/// May be null if we are already done parsing this ASTContext or the
/// ASTContext wasn't created by parsing source code.