Skip to content

Commit b6cdab5

Browse files
matborzyszkowskiigcbot
authored andcommitted
Fix DW_AT_enum_class support in DWARF
We can recognize two types of enum: traditional enum and class enum. This change fixes support of enums in `DWARF`. For traditional enum, we don't need add `DW_AT_enum_class` field.
1 parent 7b4058c commit b6cdab5

File tree

3 files changed

+137
-1
lines changed

3 files changed

+137
-1
lines changed

IGC/DebugInfo/DwarfCompileUnit.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,10 @@ void CompileUnit::constructEnumTypeDIE(DIE &Buffer, DICompositeType *CTy) {
21802180
DIType *DTy = resolve(CTy->getBaseType());
21812181
if (DTy) {
21822182
addType(&Buffer, DTy);
2183-
addFlag(&Buffer, dwarf::DW_AT_enum_class);
2183+
// Add DW_AT_enum_class when FlagEnumClass exists
2184+
if (CTy->getFlags() & DINode::FlagEnumClass) {
2185+
addFlag(&Buffer, dwarf::DW_AT_enum_class);
2186+
}
21842187
}
21852188
}
21862189

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2024 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; Test generates DWARF with traditional enum (without DW_AT_enum_class field)
10+
11+
; REQUIRES: regkeys, oneapi-readelf, llvm-14-plus
12+
13+
; RUN: llvm-as %s -o %t
14+
; RUN: ocloc compile -llvm_input -file %t -device dg2 -options "-g -cl-opt-disable -igc_opts 'ElfDumpEnable=1, DumpUseShorterName=0, DebugDumpNamePrefix=%t_'"
15+
; RUN: oneapi-readelf --debug-dump %t_OCL_simd32_foo.elf | FileCheck %s
16+
17+
; CHECK: DW_TAG_enumeration_type
18+
; CHECK: DW_AT_type : {{.*}}
19+
; CHECK: DW_AT_name : {{.*}}
20+
; CHECK: DW_AT_byte_size : {{.*}}
21+
22+
@a = addrspace(1) global i64 0, align 8, !dbg !0
23+
24+
; Function Attrs: nounwind
25+
define spir_kernel void @foo() #0 !dbg !17 {
26+
entry:
27+
%b = alloca i32, align 4
28+
call void @llvm.dbg.value(metadata i32* %b, metadata !20, metadata !22), !dbg !23
29+
store i32 0, i32* %b, align 4, !dbg !23
30+
ret void, !dbg !24
31+
}
32+
33+
; Function Attrs: nounwind readnone
34+
declare void @llvm.dbg.value(metadata, metadata, metadata) #1
35+
36+
attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" }
37+
attributes #1 = { nounwind readnone }
38+
39+
!llvm.dbg.cu = !{!8}
40+
!llvm.module.flags = !{!15, !16}
41+
42+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
43+
!1 = !DIGlobalVariable(name: "a", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true)
44+
!2 = !DIFile(filename: "enum.cpp", directory: "/tmp")
45+
!3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "x", file: !2, line: 1, size: 64, align: 64, baseType: !21, elements: !4)
46+
!4 = !{!5, !6, !7}
47+
!5 = !DIEnumerator(name: "A", value: 0)
48+
!6 = !DIEnumerator(name: "B", value: 20)
49+
!7 = !DIEnumerator(name: "C", value: 60)
50+
!8 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "clang version 14.0.5", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !9, globals: !14)
51+
!9 = !{!3, !10}
52+
!10 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "y", file: !2, line: 2, size: 32, align: 32, baseType: !21, elements: !11)
53+
!11 = !{!12}
54+
!12 = !DIEnumerator(name: "D", value: 0)
55+
!13 = !{}
56+
!14 = !{!0}
57+
!15 = !{i32 2, !"Dwarf Version", i32 4}
58+
!16 = !{i32 1, !"Debug Info Version", i32 3}
59+
!17 = distinct !DISubprogram(name: "foo", scope: !2, file: !2, line: 3, type: !18, flags: DIFlagPrototyped, unit: !8, retainedNodes: !13)
60+
!18 = !DISubroutineType(types: !19)
61+
!19 = !{null}
62+
!20 = !DILocalVariable(name: "b", scope: !17, file: !2, line: 4, type: !21)
63+
!21 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
64+
!22 = !DIExpression()
65+
!23 = !DILocation(line: 4, scope: !17)
66+
!24 = !DILocation(line: 5, scope: !17)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2024 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; Test generates DWARF with class enum (adds DW_AT_enum_class field)
10+
11+
; REQUIRES: regkeys, oneapi-readelf, llvm-14-plus
12+
13+
; RUN: llvm-as %s -o %t
14+
; RUN: ocloc compile -llvm_input -file %t -device dg2 -options "-g -cl-opt-disable -igc_opts 'ElfDumpEnable=1, DumpUseShorterName=0, DebugDumpNamePrefix=%t_'"
15+
; RUN: oneapi-readelf --debug-dump %t_OCL_simd32_foo.elf | FileCheck %s
16+
17+
; CHECK: DW_TAG_enumeration_type
18+
; CHECK: DW_AT_type : {{.*}}
19+
; CHECK: DW_AT_enum_class : {{.*}}
20+
; CHECK: DW_AT_name : {{.*}}
21+
; CHECK: DW_AT_byte_size : {{.*}}
22+
23+
@a = addrspace(1) global i64 0, align 8, !dbg !0
24+
25+
; Function Attrs: nounwind
26+
define spir_kernel void @foo() #0 !dbg !17 {
27+
entry:
28+
%b = alloca i32, align 4
29+
call void @llvm.dbg.value(metadata i32* %b, metadata !20, metadata !22), !dbg !23
30+
store i32 0, i32* %b, align 4, !dbg !23
31+
ret void, !dbg !24
32+
}
33+
34+
; Function Attrs: nounwind readnone
35+
declare void @llvm.dbg.value(metadata, metadata, metadata) #1
36+
37+
attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" }
38+
attributes #1 = { nounwind readnone }
39+
40+
!llvm.dbg.cu = !{!8}
41+
!llvm.module.flags = !{!15, !16}
42+
43+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
44+
!1 = !DIGlobalVariable(name: "a", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true)
45+
!2 = !DIFile(filename: "enum.cpp", directory: "/tmp")
46+
!3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "x", file: !2, line: 1, size: 64, align: 64, baseType: !21, flags: DIFlagEnumClass, elements: !4)
47+
!4 = !{!5, !6, !7}
48+
!5 = !DIEnumerator(name: "A", value: 0)
49+
!6 = !DIEnumerator(name: "B", value: 20)
50+
!7 = !DIEnumerator(name: "C", value: 60)
51+
!8 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "clang version 14.0.5", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !9, globals: !14)
52+
!9 = !{!3, !10}
53+
!10 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "y", file: !2, line: 2, size: 32, align: 32, baseType: !21, flags: DIFlagEnumClass, elements: !11)
54+
!11 = !{!12}
55+
!12 = !DIEnumerator(name: "D", value: 0)
56+
!13 = !{}
57+
!14 = !{!0}
58+
!15 = !{i32 2, !"Dwarf Version", i32 4}
59+
!16 = !{i32 1, !"Debug Info Version", i32 3}
60+
!17 = distinct !DISubprogram(name: "foo", scope: !2, file: !2, line: 3, type: !18, flags: DIFlagPrototyped, unit: !8, retainedNodes: !13)
61+
!18 = !DISubroutineType(types: !19)
62+
!19 = !{null}
63+
!20 = !DILocalVariable(name: "b", scope: !17, file: !2, line: 4, type: !21)
64+
!21 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
65+
!22 = !DIExpression()
66+
!23 = !DILocation(line: 4, scope: !17)
67+
!24 = !DILocation(line: 5, scope: !17)

0 commit comments

Comments
 (0)