Skip to content

Commit e00fc80

Browse files
authored
[clang][DebugInfo] Set EnumKind based on enum_extensibility attribute (#126045)
This is the 2nd part to #124752. Here we make sure to set the `DICompositeType` `EnumKind` if the enum was declared with `__attribute__((enum_extensibility(...)))`. In DWARF this will be rendered as `DW_AT_APPLE_enum_kind` and will be used by LLDB when creating `clang::EnumDecl`s from debug-info. Depends on #126044
1 parent 1608fe8 commit e00fc80

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3567,6 +3567,10 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const EnumType *Ty) {
35673567
DBuilder.createEnumerator(Enum->getName(), Enum->getInitVal()));
35683568
}
35693569

3570+
std::optional<EnumExtensibilityAttr::Kind> EnumKind;
3571+
if (auto *Attr = ED->getAttr<EnumExtensibilityAttr>())
3572+
EnumKind = Attr->getExtensibility();
3573+
35703574
// Return a CompositeType for the enum itself.
35713575
llvm::DINodeArray EltArray = DBuilder.getOrCreateArray(Enumerators);
35723576

@@ -3576,7 +3580,7 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const EnumType *Ty) {
35763580
llvm::DIType *ClassTy = getOrCreateType(ED->getIntegerType(), DefUnit);
35773581
return DBuilder.createEnumerationType(
35783582
EnumContext, ED->getName(), DefUnit, Line, Size, Align, EltArray, ClassTy,
3579-
/*RunTimeLang=*/0, Identifier, ED->isScoped());
3583+
/*RunTimeLang=*/0, Identifier, ED->isScoped(), EnumKind);
35803584
}
35813585

35823586
llvm::DIMacro *CGDebugInfo::CreateMacro(llvm::DIMacroFile *Parent,
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
2+
3+
// CHECK-NOT: enumKind
4+
// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "ClosedEnum"
5+
// CHECK-SAME: enumKind: DW_APPLE_ENUM_KIND_Closed)
6+
// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "OpenEnum"
7+
// CHECK-SAME: enumKind: DW_APPLE_ENUM_KIND_Open)
8+
// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "ClosedFlagEnum"
9+
// CHECK-SAME: enumKind: DW_APPLE_ENUM_KIND_Closed)
10+
// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "OpenFlagEnum"
11+
// CHECK-SAME: enumKind: DW_APPLE_ENUM_KIND_Open)
12+
// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "MixedEnum"
13+
// CHECK-SAME: enumKind: DW_APPLE_ENUM_KIND_Open)
14+
15+
enum Enum {
16+
E0, E1
17+
};
18+
19+
enum FlagEnum {
20+
FE0 = 1 << 0, FE1 = 1 << 1
21+
};
22+
23+
enum __attribute__((enum_extensibility(closed))) ClosedEnum {
24+
A0, A1
25+
};
26+
27+
enum __attribute__((enum_extensibility(open))) OpenEnum {
28+
B0, B1
29+
};
30+
31+
enum __attribute__((enum_extensibility(closed),flag_enum)) ClosedFlagEnum {
32+
C0 = 1 << 0, C1 = 1 << 1
33+
};
34+
35+
enum __attribute__((enum_extensibility(open),flag_enum)) OpenFlagEnum {
36+
D0 = 1 << 0, D1 = 1 << 1
37+
};
38+
39+
enum __attribute__((enum_extensibility(open), enum_extensibility(closed))) MixedEnum {
40+
M0, M1
41+
};
42+
43+
enum Enum e;
44+
enum FlagEnum fe;
45+
enum ClosedEnum ce;
46+
enum OpenEnum oe;
47+
enum ClosedFlagEnum cfe;
48+
enum OpenFlagEnum ofe;
49+
enum MixedEnum me;

0 commit comments

Comments
 (0)