Skip to content

Commit 62eeacc

Browse files
[DebugInfo] Emit DW_TAG_namelist and DW_TAG_namelist_item
This patch emits DW_TAG_namelist and DW_TAG_namelist_item for fortran namelist variables. DICompositeType is extended to support this fortran feature. Reviewed By: aprantl Differential Revision: https://reviews.llvm.org/D108553
1 parent bd2623b commit 62eeacc

File tree

4 files changed

+137
-2
lines changed

4 files changed

+137
-2
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,8 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
867867
case dwarf::DW_TAG_variant_part:
868868
case dwarf::DW_TAG_structure_type:
869869
case dwarf::DW_TAG_union_type:
870-
case dwarf::DW_TAG_class_type: {
870+
case dwarf::DW_TAG_class_type:
871+
case dwarf::DW_TAG_namelist: {
871872
// Emit the discriminator for a variant part.
872873
DIDerivedType *Discriminator = nullptr;
873874
if (Tag == dwarf::DW_TAG_variant_part) {
@@ -936,6 +937,13 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
936937
DIE &VariantPart = createAndAddDIE(Composite->getTag(), Buffer);
937938
constructTypeDIE(VariantPart, Composite);
938939
}
940+
} else if (Tag == dwarf::DW_TAG_namelist) {
941+
auto *Var = dyn_cast<DINode>(Element);
942+
auto *VarDIE = getDIE(Var);
943+
if (VarDIE) {
944+
DIE &ItemDie = createAndAddDIE(dwarf::DW_TAG_namelist_item, Buffer);
945+
addDIEEntry(ItemDie, dwarf::DW_AT_namelist_item, *VarDIE);
946+
}
939947
}
940948
}
941949

llvm/lib/IR/Verifier.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,8 @@ void Verifier::visitDICompositeType(const DICompositeType &N) {
10961096
N.getTag() == dwarf::DW_TAG_union_type ||
10971097
N.getTag() == dwarf::DW_TAG_enumeration_type ||
10981098
N.getTag() == dwarf::DW_TAG_class_type ||
1099-
N.getTag() == dwarf::DW_TAG_variant_part,
1099+
N.getTag() == dwarf::DW_TAG_variant_part ||
1100+
N.getTag() == dwarf::DW_TAG_namelist,
11001101
"invalid tag", &N);
11011102

11021103
AssertDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope());

llvm/test/DebugInfo/X86/namelist1.ll

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
; Namelist is a fortran feature, this test checks whether DW_TAG_namelist and
2+
; DW_TAG_namelist_item attributes are emitted correctly.
3+
;
4+
; RUN: llc -O0 -mtriple=x86_64-unknown-linux-gnu %s -filetype=obj -o %t.o
5+
; RUN: llvm-dwarfdump %t.o | FileCheck %s
6+
;
7+
; CHECK: [[ITEM1:0x.+]]: DW_TAG_variable
8+
; CHECK: DW_AT_name ("a")
9+
; CHECK: [[ITEM2:0x.+]]: DW_TAG_variable
10+
; CHECK: DW_AT_name ("b")
11+
; CHECK: DW_TAG_namelist
12+
; CHECK: DW_AT_name ("nml")
13+
; CHECK: DW_TAG_namelist_item
14+
; CHECK: DW_AT_namelist_item ([[ITEM1]])
15+
; CHECK: DW_TAG_namelist_item
16+
; CHECK: DW_AT_namelist_item ([[ITEM2]])
17+
;
18+
; generated from
19+
;
20+
; program main
21+
;
22+
; integer :: a=1, b
23+
; namelist /nml/ a, b
24+
;
25+
; a = 10
26+
; b = 20
27+
; Write(*,nml)
28+
;
29+
; end program main
30+
31+
source_filename = "namelist.ll"
32+
33+
define void @MAIN_() !dbg !2 {
34+
L.entry:
35+
%b_350 = alloca i32, align 4
36+
call void @llvm.dbg.declare(metadata i32* %b_350, metadata !12, metadata !DIExpression()), !dbg !13
37+
call void @llvm.dbg.value(metadata i32 1, metadata !14, metadata !DIExpression()), !dbg !13
38+
ret void, !dbg !17
39+
}
40+
41+
declare void @llvm.dbg.declare(metadata, metadata, metadata)
42+
declare void @llvm.dbg.value(metadata, metadata, metadata)
43+
44+
!llvm.module.flags = !{!10, !11}
45+
!llvm.dbg.cu = !{!4}
46+
47+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression(DW_OP_plus_uconst, 120))
48+
!1 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 3, type: !9, isLocal: true, isDefinition: true)
49+
!2 = distinct !DISubprogram(name: "main", scope: !4, file: !3, line: 1, type: !7, scopeLine: 1, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagMainSubprogram, unit: !4)
50+
!3 = !DIFile(filename: "namelist.f90", directory: "/dir")
51+
!4 = distinct !DICompileUnit(language: DW_LANG_Fortran90, file: !3, producer: " F90 Flang - 1.5 2017-05-01", isOptimized: false, flags: "'+flang -g namelist.f90 -S -emit-llvm'", runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !6, imports: !5, nameTableKind: None)
52+
!5 = !{}
53+
!6 = !{!0}
54+
!7 = !DISubroutineType(cc: DW_CC_program, types: !8)
55+
!8 = !{null}
56+
!9 = !DIBasicType(name: "integer", size: 32, align: 32, encoding: DW_ATE_signed)
57+
!10 = !{i32 2, !"Dwarf Version", i32 4}
58+
!11 = !{i32 2, !"Debug Info Version", i32 3}
59+
!12 = !DILocalVariable(name: "b", scope: !2, file: !3, line: 3, type: !9)
60+
!13 = !DILocation(line: 0, scope: !2)
61+
!14 = distinct !DILocalVariable(scope: !2, file: !3, line: 2, type: !15, flags: DIFlagArtificial)
62+
!15 = !DICompositeType(tag: DW_TAG_namelist, name: "nml", scope: !2, file: !3, elements: !16)
63+
!16 = !{!1, !12}
64+
!17 = !DILocation(line: 10, column: 1, scope: !2)

llvm/test/DebugInfo/X86/namelist2.ll

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
; Namelist is a fortran feature, this test checks whether DW_TAG_namelist and
2+
; DW_TAG_namelist_item attributes are emitted correctly, when declared inside
3+
; a module.
4+
;
5+
; RUN: llc -O0 -mtriple=x86_64-unknown-linux-gnu %s -filetype=obj -o %t.o
6+
; RUN: llvm-dwarfdump %t.o | FileCheck %s
7+
;
8+
; CHECK: [[ITEM1:0x.+]]: DW_TAG_variable
9+
; CHECK: DW_AT_name ("aa")
10+
; CHECK: [[ITEM2:0x.+]]: DW_TAG_variable
11+
; CHECK: DW_AT_name ("bb")
12+
; CHECK: DW_TAG_namelist
13+
; CHECK: DW_AT_name ("nml")
14+
; CHECK: DW_TAG_namelist_item
15+
; CHECK: DW_AT_namelist_item ([[ITEM1]])
16+
; CHECK: DW_TAG_namelist_item
17+
; CHECK: DW_AT_namelist_item ([[ITEM2]])
18+
;
19+
; generated from
20+
;
21+
; module mm
22+
; integer :: aa=10, bb=20
23+
; namelist /nml/ aa, bb
24+
; end module mm
25+
;
26+
; subroutine test()
27+
; use mm
28+
; write(*,nml)
29+
; end subroutine test
30+
;
31+
; Program namelist
32+
; Call test()
33+
; End Program
34+
35+
source_filename = "namelist2.ll"
36+
37+
!llvm.module.flags = !{!19, !20}
38+
!llvm.dbg.cu = !{!4}
39+
40+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
41+
!1 = distinct !DIGlobalVariable(name: "aa", scope: !2, file: !3, line: 2, type: !9, isLocal: false, isDefinition: true)
42+
!2 = !DIModule(scope: !4, name: "mm", file: !3, line: 1)
43+
!3 = !DIFile(filename: "namelist2.f90", directory: "/dir")
44+
!4 = distinct !DICompileUnit(language: DW_LANG_Fortran90, file: !3, producer: " F90 Flang - 1.5 2017-05-01", isOptimized: false, flags: "'+flang -g namelist2.f90 -S -emit-llvm'", runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !6, imports: !14, nameTableKind: None)
45+
!5 = !{}
46+
!6 = !{!0, !7, !10}
47+
!7 = !DIGlobalVariableExpression(var: !8, expr: !DIExpression(DW_OP_plus_uconst, 4))
48+
!8 = distinct !DIGlobalVariable(name: "bb", scope: !2, file: !3, line: 2, type: !9, isLocal: false, isDefinition: true)
49+
!9 = !DIBasicType(name: "integer", size: 32, align: 32, encoding: DW_ATE_signed)
50+
!10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression())
51+
!11 = distinct !DIGlobalVariable(name: "nml", scope: !2, file: !3, line: 2, type: !12, isLocal: false, isDefinition: true)
52+
!12 = !DICompositeType(tag: DW_TAG_namelist, name: "nml", file: !3, elements: !13)
53+
!13 = !{!1, !8}
54+
!14 = !{!15}
55+
!15 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !16, entity: !2, file: !3, line: 6)
56+
!16 = distinct !DISubprogram(name: "test", scope: !4, file: !3, line: 6, type: !17, scopeLine: 6, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition, unit: !4)
57+
!17 = !DISubroutineType(types: !18)
58+
!18 = !{null}
59+
!19 = !{i32 2, !"Dwarf Version", i32 4}
60+
!20 = !{i32 2, !"Debug Info Version", i32 3}
61+
!21 = distinct !DISubprogram(name: "namelist", scope: !4, file: !3, line: 11, type: !22, scopeLine: 11, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagMainSubprogram, unit: !4)
62+
!22 = !DISubroutineType(cc: DW_CC_program, types: !18)

0 commit comments

Comments
 (0)