Skip to content

[clang][DebugInfo] Set EnumKind based on enum_extensibility attribute #126045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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,
Expand Down
49 changes: 49 additions & 0 deletions clang/test/CodeGen/debug-info-enum-extensibility.c
Original file line number Diff line number Diff line change
@@ -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;