[clang] e00fc80 - [clang][DebugInfo] Set EnumKind based on enum_extensibility attribute (#126045)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 7 01:28:13 PST 2025
Author: Michael Buch
Date: 2025-02-07T09:28:10Z
New Revision: e00fc80c194b3742cd387b7cc74a5fd7ab775bf0
URL: https://github.com/llvm/llvm-project/commit/e00fc80c194b3742cd387b7cc74a5fd7ab775bf0
DIFF: https://github.com/llvm/llvm-project/commit/e00fc80c194b3742cd387b7cc74a5fd7ab775bf0.diff
LOG: [clang][DebugInfo] Set EnumKind based on enum_extensibility attribute (#126045)
This is the 2nd part to
https://github.com/llvm/llvm-project/pull/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 https://github.com/llvm/llvm-project/pull/126044
Added:
clang/test/CodeGen/debug-info-enum-extensibility.c
Modified:
clang/lib/CodeGen/CGDebugInfo.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index db595796c067e98..d5b584ec0f2e95b 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3567,6 +3567,10 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const EnumType *Ty) {
DBuilder.createEnumerator(Enum->getName(), Enum->getInitVal()));
}
+ std::optional<EnumExtensibilityAttr::Kind> EnumKind;
+ if (auto *Attr = ED->getAttr<EnumExtensibilityAttr>())
+ EnumKind = Attr->getExtensibility();
+
// Return a CompositeType for the enum itself.
llvm::DINodeArray EltArray = DBuilder.getOrCreateArray(Enumerators);
@@ -3576,7 +3580,7 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const EnumType *Ty) {
llvm::DIType *ClassTy = getOrCreateType(ED->getIntegerType(), DefUnit);
return DBuilder.createEnumerationType(
EnumContext, ED->getName(), DefUnit, Line, Size, Align, EltArray, ClassTy,
- /*RunTimeLang=*/0, Identifier, ED->isScoped());
+ /*RunTimeLang=*/0, Identifier, ED->isScoped(), EnumKind);
}
llvm::DIMacro *CGDebugInfo::CreateMacro(llvm::DIMacroFile *Parent,
diff --git a/clang/test/CodeGen/debug-info-enum-extensibility.c b/clang/test/CodeGen/debug-info-enum-extensibility.c
new file mode 100644
index 000000000000000..4f8a42bff3f0195
--- /dev/null
+++ b/clang/test/CodeGen/debug-info-enum-extensibility.c
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
+
+// CHECK-NOT: enumKind
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "ClosedEnum"
+// CHECK-SAME: enumKind: DW_APPLE_ENUM_KIND_Closed)
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "OpenEnum"
+// CHECK-SAME: enumKind: DW_APPLE_ENUM_KIND_Open)
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "ClosedFlagEnum"
+// CHECK-SAME: enumKind: DW_APPLE_ENUM_KIND_Closed)
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "OpenFlagEnum"
+// CHECK-SAME: enumKind: DW_APPLE_ENUM_KIND_Open)
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "MixedEnum"
+// CHECK-SAME: enumKind: DW_APPLE_ENUM_KIND_Open)
+
+enum Enum {
+ E0, E1
+};
+
+enum FlagEnum {
+ FE0 = 1 << 0, FE1 = 1 << 1
+};
+
+enum __attribute__((enum_extensibility(closed))) ClosedEnum {
+ A0, A1
+};
+
+enum __attribute__((enum_extensibility(open))) OpenEnum {
+ B0, B1
+};
+
+enum __attribute__((enum_extensibility(closed),flag_enum)) ClosedFlagEnum {
+ C0 = 1 << 0, C1 = 1 << 1
+};
+
+enum __attribute__((enum_extensibility(open),flag_enum)) OpenFlagEnum {
+ D0 = 1 << 0, D1 = 1 << 1
+};
+
+enum __attribute__((enum_extensibility(open), enum_extensibility(closed))) MixedEnum {
+ M0, M1
+};
+
+enum Enum e;
+enum FlagEnum fe;
+enum ClosedEnum ce;
+enum OpenEnum oe;
+enum ClosedFlagEnum cfe;
+enum OpenFlagEnum ofe;
+enum MixedEnum me;
More information about the cfe-commits
mailing list