Skip to content

Commit 0cdb467

Browse files
authored
[lldb][TypeSystemClang] Create EnumExtensibilityAttr from DW_AT_APPLE_enum_kind (llvm#126221)
This patch consumes the `DW_AT_APPLE_enum_kind` attribute added in llvm#124752 and turns it into a Clang attribute in the AST. This will currently be used by the Swift language plugin when it creates `EnumDecl`s from debug-info and passes it to Swift compiler, which expects these attributes
1 parent 16df836 commit 0cdb467

File tree

5 files changed

+57
-9
lines changed

5 files changed

+57
-9
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,10 @@ ParsedDWARFTypeAttributes::ParsedDWARFTypeAttributes(const DWARFDIE &die) {
492492
case DW_AT_reference:
493493
ref_qual = clang::RQ_LValue;
494494
break;
495+
case DW_AT_APPLE_enum_kind:
496+
enum_kind = static_cast<clang::EnumExtensibilityAttr::Kind>(
497+
form_value.Unsigned());
498+
break;
495499
}
496500
}
497501
}
@@ -1001,9 +1005,10 @@ TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc,
10011005
}
10021006

10031007
CompilerType clang_type = m_ast.CreateEnumerationType(
1004-
attrs.name.GetStringRef(), GetClangDeclContextContainingDIE(def_die, nullptr),
1008+
attrs.name.GetStringRef(),
1009+
GetClangDeclContextContainingDIE(def_die, nullptr),
10051010
GetOwningClangModule(def_die), attrs.decl, enumerator_clang_type,
1006-
attrs.is_scoped_enum);
1011+
attrs.is_scoped_enum, attrs.enum_kind);
10071012
TypeSP type_sp =
10081013
dwarf->MakeType(def_die.GetID(), attrs.name, attrs.byte_size, nullptr,
10091014
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
@@ -568,6 +568,10 @@ struct ParsedDWARFTypeAttributes {
568568
///< Indicates ref-qualifier of C++ member function if present.
569569
///< Is RQ_None otherwise.
570570
clang::RefQualifierKind ref_qual = clang::RQ_None;
571+
572+
///< Has a value if this DIE represents an enum that was declared
573+
///< with enum_extensibility.
574+
std::optional<clang::EnumExtensibilityAttr::Kind> enum_kind;
571575
};
572576

573577
#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
@@ -2303,7 +2303,8 @@ CompilerType TypeSystemClang::GetOrCreateStructForIdentifier(
23032303
CompilerType TypeSystemClang::CreateEnumerationType(
23042304
llvm::StringRef name, clang::DeclContext *decl_ctx,
23052305
OptionalClangModuleID owning_module, const Declaration &decl,
2306-
const CompilerType &integer_clang_type, bool is_scoped) {
2306+
const CompilerType &integer_clang_type, bool is_scoped,
2307+
std::optional<clang::EnumExtensibilityAttr::Kind> enum_kind) {
23072308
// TODO: Do something intelligent with the Declaration object passed in
23082309
// like maybe filling in the SourceLocation with it...
23092310
ASTContext &ast = getASTContext();
@@ -2321,6 +2322,10 @@ CompilerType TypeSystemClang::CreateEnumerationType(
23212322
if (decl_ctx)
23222323
decl_ctx->addDecl(enum_decl);
23232324

2325+
if (enum_kind)
2326+
enum_decl->addAttr(
2327+
clang::EnumExtensibilityAttr::CreateImplicit(ast, *enum_kind));
2328+
23242329
// TODO: check if we should be setting the promotion type too?
23252330
enum_decl->setIntegerType(ClangUtil::GetQualType(integer_clang_type));
23262331

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

Lines changed: 7 additions & 6 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"
@@ -498,12 +499,12 @@ class TypeSystemClang : public TypeSystem {
498499
bool is_vector);
499500

500501
// Enumeration Types
501-
CompilerType CreateEnumerationType(llvm::StringRef name,
502-
clang::DeclContext *decl_ctx,
503-
OptionalClangModuleID owning_module,
504-
const Declaration &decl,
505-
const CompilerType &integer_qual_type,
506-
bool is_scoped);
502+
CompilerType CreateEnumerationType(
503+
llvm::StringRef name, clang::DeclContext *decl_ctx,
504+
OptionalClangModuleID owning_module, const Declaration &decl,
505+
const CompilerType &integer_qual_type, bool is_scoped,
506+
std::optional<clang::EnumExtensibilityAttr::Kind> enum_kind =
507+
std::nullopt);
507508

508509
// Integer type functions
509510

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// UNSUPPORTED: system-linux, system-windows
2+
3+
// RUN: %clangxx_host %s -c -g -o %t
4+
// RUN: %lldb %t \
5+
// RUN: -o "target var gClosed gOpen gNS gNSOpts" \
6+
// RUN: -o "image dump ast" \
7+
// RUN: 2>&1 | FileCheck %s
8+
9+
#import <Foundation/Foundation.h>
10+
11+
enum __attribute__((enum_extensibility(closed))) Closed { C1 } gClosed;
12+
13+
enum __attribute__((enum_extensibility(open))) Open { O1 } gOpen;
14+
15+
typedef NS_ENUM(int, NS) { N1 } gNS;
16+
17+
typedef NS_OPTIONS(int, NSO) { OPT1 } gNSOpts;
18+
19+
// CHECK: EnumDecl {{.*}} Closed
20+
// CHECK-NEXT: |-EnumExtensibilityAttr {{.*}} Closed
21+
// CHECK-NEXT: `-EnumConstantDecl {{.*}} C1 'Closed'
22+
23+
// CHECK: EnumDecl {{.*}} Open
24+
// CHECK-NEXT: |-EnumExtensibilityAttr {{.*}} Open
25+
// CHECK-NEXT: `-EnumConstantDecl {{.*}} O1 'Open'
26+
27+
// CHECK: EnumDecl {{.*}} NS
28+
// CHECK-NEXT: |-EnumExtensibilityAttr {{.*}} Open
29+
// CHECK-NEXT: `-EnumConstantDecl {{.*}} N1 'NS'
30+
31+
// CHECK: EnumDecl {{.*}} NSO
32+
// CHECK-NEXT: |-EnumExtensibilityAttr {{.*}} Open
33+
// CHECK-NEXT: `-EnumConstantDecl {{.*}} OPT1 'NSO'

0 commit comments

Comments
 (0)