Skip to content

Commit 0647828

Browse files
committed
Retain unused nested enum type information
1 parent 2b983a2 commit 0647828

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,13 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, llvm::DIType *RecordTy,
19011901
return GV;
19021902
}
19031903

1904+
void CGDebugInfo::CollectRecordEnumType(const EnumDecl *ED, SmallVectorImpl<llvm::Metadata *> &elements) {
1905+
QualType Ty = CGM.getContext().getTypeDeclType(ED);
1906+
SourceLocation Loc = ED->getLocation();
1907+
if (llvm::DIType *enumType = getOrCreateType(Ty, getOrCreateFile(Loc)))
1908+
elements.push_back(enumType);
1909+
}
1910+
19041911
void CGDebugInfo::CollectRecordNormalField(
19051912
const FieldDecl *field, uint64_t OffsetInBits, llvm::DIFile *tunit,
19061913
SmallVectorImpl<llvm::Metadata *> &elements, llvm::DIType *RecordTy,
@@ -1987,6 +1994,8 @@ void CGDebugInfo::CollectRecordFields(
19871994

19881995
// Bump field number for next field.
19891996
++fieldNo;
1997+
} else if (const auto *enumType = dyn_cast<EnumDecl>(I)) {
1998+
CollectRecordEnumType(enumType, elements);
19901999
} else if (CGM.getCodeGenOpts().EmitCodeView) {
19912000
// Debug info for nested types is included in the member list only for
19922001
// CodeView.

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ class CGDebugInfo {
370370
llvm::DIDerivedType *CreateRecordStaticField(const VarDecl *Var,
371371
llvm::DIType *RecordTy,
372372
const RecordDecl *RD);
373+
void CollectRecordEnumType(const EnumDecl *ED, SmallVectorImpl<llvm::Metadata *> &elements);
373374
void CollectRecordNormalField(const FieldDecl *Field, uint64_t OffsetInBits,
374375
llvm::DIFile *F,
375376
SmallVectorImpl<llvm::Metadata *> &E,
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
; RUN: %clang_cc1 -fno-eliminate-unused-debug-types -emit-llvm -o - %s | FileCheck %s
2+
; RUN: llvm-dwarfdump %t | FileCheck %s
3+
4+
;CHECK: DW_TAG_structure_type
5+
;CHECK-NEXT: DW_AT_calling_convention (DW_CC_pass_by_value)
6+
;CHECK-NEXT: DW_AT_name ("Type")
7+
;CHECK-NEXT: DW_AT_byte_size (0x04)
8+
;CHECK-NEXT: DW_AT_decl_file ("/iusers/ykhatavk/project_ics/llvm-project/debug_issue/enump.cpp")
9+
;CHECK-NEXT: DW_AT_decl_line (1)
10+
;CHECK: DW_TAG_member
11+
;CHECK-NEXT: DW_AT_name ("value")
12+
;CHECK-NEXT: DW_AT_type (0x0000004f "int")
13+
;CHECK-NEXT: DW_AT_decl_file ("/iusers/ykhatavk/project_ics/llvm-project/debug_issue/enump.cpp")
14+
;CHECK-NEXT: DW_AT_decl_line (3)
15+
;CHECK-NEXT: DW_AT_data_member_location (0x00)
16+
;CHECK: DW_TAG_enumeration_type
17+
;CHECK-NEXT: DW_AT_type (0x00000053 "unsigned int")
18+
;CHECK-NEXT: DW_AT_byte_size (0x04)
19+
;CHECK-NEXT: DW_AT_decl_file ("/iusers/ykhatavk/project_ics/llvm-project/debug_issue/enump.cpp")
20+
;CHECK-NEXT: DW_AT_decl_line (2)
21+
;CHECK: DW_TAG_enumerator
22+
;CHECK-NEXT: DW_AT_name ("Unused")
23+
;CHECK-NEXT: DW_AT_const_value (0)
24+
25+
; ModuleID = 'enump.cpp'
26+
source_filename = "enump.cpp"
27+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
28+
target triple = "x86_64-unknown-linux-gnu"
29+
30+
%struct.Type = type { i32 }
31+
32+
$_ZN4TypeC2Ev = comdat any
33+
34+
; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable
35+
define dso_local noundef i32 @main() #0 !dbg !20 {
36+
entry:
37+
%retval = alloca i32, align 4
38+
%t = alloca %struct.Type, align 4
39+
store i32 0, ptr %retval, align 4
40+
#dbg_declare(ptr %t, !24, !DIExpression(), !25)
41+
call void @_ZN4TypeC2Ev(ptr noundef nonnull align 4 dereferenceable(4) %t) #2, !dbg !25
42+
%value = getelementptr inbounds nuw %struct.Type, ptr %t, i32 0, i32 0, !dbg !26
43+
%0 = load i32, ptr %value, align 4, !dbg !26
44+
ret i32 %0, !dbg !27
45+
}
46+
47+
; Function Attrs: mustprogress noinline nounwind optnone uwtable
48+
define linkonce_odr dso_local void @_ZN4TypeC2Ev(ptr noundef nonnull align 4 dereferenceable(4) %this) unnamed_addr #1 comdat align 2 !dbg !28 {
49+
entry:
50+
%this.addr = alloca ptr, align 8
51+
store ptr %this, ptr %this.addr, align 8
52+
#dbg_declare(ptr %this.addr, !33, !DIExpression(), !35)
53+
%this1 = load ptr, ptr %this.addr, align 8
54+
%value = getelementptr inbounds nuw %struct.Type, ptr %this1, i32 0, i32 0, !dbg !36
55+
store i32 0, ptr %value, align 4, !dbg !36
56+
ret void, !dbg !37
57+
}
58+
59+
attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
60+
attributes #1 = { mustprogress noinline nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
61+
attributes #2 = { nounwind }
62+
63+
!llvm.dbg.cu = !{!0}
64+
!llvm.module.flags = !{!12, !13, !14, !15, !16, !17, !18}
65+
!llvm.ident = !{!19}
66+
67+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 21.0.0git (https://github.com/llvm/llvm-project.git 2b983a24583dd4e131d727717872a56712b5dd52)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !11, splitDebugInlining: false, nameTableKind: None)
68+
!1 = !DIFile(filename: "enump.cpp", directory: "/iusers/ykhatavk/project_ics/llvm-project/debug_issue", checksumkind: CSK_MD5, checksum: "35ec0482db78c9e464e8bf8cd231d5b9")
69+
!2 = !{!3}
70+
!3 = !DICompositeType(tag: DW_TAG_enumeration_type, scope: !4, file: !1, line: 2, baseType: !8, size: 32, elements: !9, identifier: "_ZTSN4TypeUt_E")
71+
!4 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Type", file: !1, line: 1, size: 32, flags: DIFlagTypePassByValue | DIFlagNonTrivial, elements: !5, identifier: "_ZTS4Type")
72+
!5 = !{!3, !6}
73+
!6 = !DIDerivedType(tag: DW_TAG_member, name: "value", scope: !4, file: !1, line: 3, baseType: !7, size: 32)
74+
!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
75+
!8 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
76+
!9 = !{!10}
77+
!10 = !DIEnumerator(name: "Unused", value: 0, isUnsigned: true)
78+
!11 = !{!4}
79+
!12 = !{i32 7, !"Dwarf Version", i32 5}
80+
!13 = !{i32 2, !"Debug Info Version", i32 3}
81+
!14 = !{i32 1, !"wchar_size", i32 4}
82+
!15 = !{i32 8, !"PIC Level", i32 2}
83+
!16 = !{i32 7, !"PIE Level", i32 2}
84+
!17 = !{i32 7, !"uwtable", i32 2}
85+
!18 = !{i32 7, !"frame-pointer", i32 2}
86+
!19 = !{!"clang version 21.0.0git (https://github.com/llvm/llvm-project.git 2b983a24583dd4e131d727717872a56712b5dd52)"}
87+
!20 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 5, type: !21, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !23)
88+
!21 = !DISubroutineType(types: !22)
89+
!22 = !{!7}
90+
!23 = !{}
91+
!24 = !DILocalVariable(name: "t", scope: !20, file: !1, line: 6, type: !4)
92+
!25 = !DILocation(line: 6, column: 10, scope: !20)
93+
!26 = !DILocation(line: 7, column: 14, scope: !20)
94+
!27 = !DILocation(line: 7, column: 5, scope: !20)
95+
!28 = distinct !DISubprogram(name: "Type", linkageName: "_ZN4TypeC2Ev", scope: !4, file: !1, line: 1, type: !29, scopeLine: 1, flags: DIFlagArtificial | DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !32, retainedNodes: !23)
96+
!29 = !DISubroutineType(types: !30)
97+
!30 = !{null, !31}
98+
!31 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !4, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
99+
!32 = !DISubprogram(name: "Type", scope: !4, type: !29, flags: DIFlagArtificial | DIFlagPrototyped, spFlags: 0)
100+
!33 = !DILocalVariable(name: "this", arg: 1, scope: !28, type: !34, flags: DIFlagArtificial | DIFlagObjectPointer)
101+
!34 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !4, size: 64)
102+
!35 = !DILocation(line: 0, scope: !28)
103+
!36 = !DILocation(line: 3, column: 9, scope: !28)
104+
!37 = !DILocation(line: 1, column: 8, scope: !28)

0 commit comments

Comments
 (0)