Skip to content
Closed
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
10 changes: 10 additions & 0 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1901,6 +1901,14 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, llvm::DIType *RecordTy,
return GV;
}

void CGDebugInfo::CollectRecordEnumType(
const EnumDecl *ED, SmallVectorImpl<llvm::Metadata *> &elements) {
QualType Ty = CGM.getContext().getTypeDeclType(ED);
SourceLocation Loc = ED->getLocation();
if (llvm::DIType *enumType = getOrCreateType(Ty, getOrCreateFile(Loc)))
elements.push_back(enumType);
}

void CGDebugInfo::CollectRecordNormalField(
const FieldDecl *field, uint64_t OffsetInBits, llvm::DIFile *tunit,
SmallVectorImpl<llvm::Metadata *> &elements, llvm::DIType *RecordTy,
Expand Down Expand Up @@ -1987,6 +1995,8 @@ void CGDebugInfo::CollectRecordFields(

// Bump field number for next field.
++fieldNo;
} else if (const auto *enumType = dyn_cast<EnumDecl>(I)) {
CollectRecordEnumType(enumType, elements);
} else if (CGM.getCodeGenOpts().EmitCodeView) {
// Debug info for nested types is included in the member list only for
// CodeView.
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CodeGen/CGDebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ class CGDebugInfo {
llvm::DIDerivedType *CreateRecordStaticField(const VarDecl *Var,
llvm::DIType *RecordTy,
const RecordDecl *RD);
void CollectRecordEnumType(const EnumDecl *ED,
SmallVectorImpl<llvm::Metadata *> &elements);
void CollectRecordNormalField(const FieldDecl *Field, uint64_t OffsetInBits,
llvm::DIFile *F,
SmallVectorImpl<llvm::Metadata *> &E,
Expand Down
26 changes: 26 additions & 0 deletions clang/test/CodeGen/unused_nested_enump.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// RUN: %clang_cc1 -debug-info-kind=unused-types -emit-llvm -o - %s | FileCheck %s

struct Type {
enum { Unused };
int value = 0;
};
int main() {
Type t;
return t.value;
}

// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type
// CHECK-SAME: scope: ![[STRUCT:[0-9]+]]
// CHECK-SAME: elements: ![[ELEMENTS:[0-9]+]]

// CHECK: ![[STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type
// CHECK-SAME: elements: ![[STRUCT_ELEMENTS:[0-9]+]]

// CHECK: ![[STRUCT_ELEMENTS]] = !{![[ENUM_MEMBER:[0-9]+]], ![[VALUE_MEMBER:[0-9]+]]}

// CHECK: ![[VALUE_MEMBER]] = !DIDerivedType(tag: DW_TAG_member
// CHECK-SAME: name: "value"
// CHECK-SAME: scope: ![[STRUCT]]

// CHECK: ![[ELEMENTS]] = !{![[ENUMERATOR:[0-9]+]]}
// CHECK: ![[ENUMERATOR]] = !DIEnumerator(name: "Unused", value: 0