Skip to content

Commit 5e1f334

Browse files
authored
Merge pull request #9976 from swiftlang/lldb/enum-extensibility-to-20240723
[lldb][TypeSystemClang] Create EnumExtensibilityAttr from DW_AT_APPLE_enum_kind
2 parents f29572a + 2b225ac commit 5e1f334

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,10 @@ ParsedDWARFTypeAttributes::ParsedDWARFTypeAttributes(const DWARFDIE &die) {
450450
case DW_AT_reference:
451451
ref_qual = clang::RQ_LValue;
452452
break;
453+
case DW_AT_APPLE_enum_kind:
454+
enum_kind = static_cast<clang::EnumExtensibilityAttr::Kind>(
455+
form_value.Unsigned());
456+
break;
453457
}
454458
}
455459
}
@@ -1041,9 +1045,10 @@ TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc,
10411045
}
10421046

10431047
CompilerType clang_type = m_ast.CreateEnumerationType(
1044-
attrs.name.GetStringRef(), GetClangDeclContextContainingDIE(def_die, nullptr),
1048+
attrs.name.GetStringRef(),
1049+
GetClangDeclContextContainingDIE(def_die, nullptr),
10451050
GetOwningClangModule(def_die), attrs.decl, enumerator_clang_type,
1046-
attrs.is_scoped_enum);
1051+
attrs.is_scoped_enum, attrs.enum_kind);
10471052
TypeSP type_sp =
10481053
dwarf->MakeType(def_die.GetID(), attrs.name, attrs.byte_size, nullptr,
10491054
attrs.type.Reference().GetID(), Type::eEncodingIsUID,

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,10 @@ struct ParsedDWARFTypeAttributes {
538538
clang::RQ_None; ///< Indicates ref-qualifier of
539539
///< C++ member function if present.
540540
///< Is RQ_None otherwise.
541+
542+
///< Has a value if this DIE represents an enum that was declared
543+
///< with enum_extensibility.
544+
std::optional<clang::EnumExtensibilityAttr::Kind> enum_kind;
541545
};
542546

543547
#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFASTPARSERCLANG_H

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2409,7 +2409,8 @@ CompilerType TypeSystemClang::GetOrCreateStructForIdentifier(
24092409
clang::EnumDecl *TypeSystemClang::CreateEnumerationDecl(
24102410
llvm::StringRef name, clang::DeclContext *decl_ctx,
24112411
OptionalClangModuleID owning_module, const Declaration &decl,
2412-
const CompilerType &integer_clang_type, bool is_scoped) {
2412+
const CompilerType &integer_clang_type, bool is_scoped,
2413+
std::optional<clang::EnumExtensibilityAttr::Kind> enum_kind) {
24132414
// TODO: Do something intelligent with the Declaration object passed in
24142415
// like maybe filling in the SourceLocation with it...
24152416
ASTContext &ast = getASTContext();
@@ -2427,6 +2428,10 @@ clang::EnumDecl *TypeSystemClang::CreateEnumerationDecl(
24272428
if (decl_ctx)
24282429
decl_ctx->addDecl(enum_decl);
24292430

2431+
if (enum_kind)
2432+
enum_decl->addAttr(
2433+
clang::EnumExtensibilityAttr::CreateImplicit(ast, *enum_kind));
2434+
24302435
// TODO: check if we should be setting the promotion type too?
24312436
enum_decl->setIntegerType(ClangUtil::GetQualType(integer_clang_type));
24322437

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "clang/AST/ASTContext.h"
2424
#include "clang/AST/ASTFwd.h"
25+
#include "clang/AST/Attr.h"
2526
#include "clang/AST/Decl.h"
2627
#include "clang/AST/TemplateBase.h"
2728
#include "clang/AST/Type.h"
@@ -539,21 +540,22 @@ class TypeSystemClang : public TypeSystem {
539540
size_t element_count, bool is_vector);
540541

541542
// Enumeration Types
542-
clang::EnumDecl *CreateEnumerationDecl(llvm::StringRef name,
543-
clang::DeclContext *decl_ctx,
544-
OptionalClangModuleID owning_module,
545-
const Declaration &decl,
546-
const CompilerType &integer_qual_type,
547-
bool is_scoped);
548-
549-
CompilerType CreateEnumerationType(llvm::StringRef name,
550-
clang::DeclContext *decl_ctx,
551-
OptionalClangModuleID owning_module,
552-
const Declaration &decl,
553-
const CompilerType &integer_qual_type,
554-
bool is_scoped) {
555-
clang::EnumDecl *enum_decl = CreateEnumerationDecl(
556-
name, decl_ctx, owning_module, decl, integer_qual_type, is_scoped);
543+
clang::EnumDecl *CreateEnumerationDecl(
544+
llvm::StringRef name, clang::DeclContext *decl_ctx,
545+
OptionalClangModuleID owning_module, const Declaration &decl,
546+
const CompilerType &integer_qual_type, bool is_scoped,
547+
std::optional<clang::EnumExtensibilityAttr::Kind> enum_kind =
548+
std::nullopt);
549+
550+
CompilerType CreateEnumerationType(
551+
llvm::StringRef name, clang::DeclContext *decl_ctx,
552+
OptionalClangModuleID owning_module, const Declaration &decl,
553+
const CompilerType &integer_qual_type, bool is_scoped,
554+
std::optional<clang::EnumExtensibilityAttr::Kind> enum_kind =
555+
std::nullopt) {
556+
clang::EnumDecl *enum_decl =
557+
CreateEnumerationDecl(name, decl_ctx, owning_module, decl,
558+
integer_qual_type, is_scoped, enum_kind);
557559
return GetType(getASTContext().getTagDeclType(enum_decl));
558560
}
559561

0 commit comments

Comments
 (0)