[PATCH] D41696: [DebugInfo] Emit DWARF reference for DIVariable 'count' in DISubrange
Sander de Smalen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 3 03:03:37 PST 2018
sdesmalen created this revision.
sdesmalen added reviewers: echristo, pcc, aprantl, dexonsmith, clayborg, kristof.beyls.
Herald added subscribers: JDevlieghere, rengolin, aemerson.
This patch implements the codegen of DWARF debug info for non-constant
'count' fields for DISubrange.
This is patch [2/3] in a series to extend LLVM's DISubrange Metadata
node to support debugging of C99 variable length arrays and vectors with
runtime length like the Scalable Vector Extension for AArch64. It is
also a first step towards representing more complex cases like arrays
in Fortran.
https://reviews.llvm.org/D41696
Files:
lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
lib/CodeGen/AsmPrinter/DwarfUnit.cpp
test/DebugInfo/Generic/disubrange.ll
Index: test/DebugInfo/Generic/disubrange.ll
===================================================================
--- /dev/null
+++ test/DebugInfo/Generic/disubrange.ll
@@ -0,0 +1,40 @@
+; RUN: %llc_dwarf -O0 -filetype=obj < %s > %t
+; RUN: llvm-dwarfdump -verbose %t | FileCheck %s
+
+; CHECK-DAG: DW_AT_count [DW_FORM_ref4] (cu + {{.*}} => {[[NODE:[0-9a-zA-Zx]+]]})
+; CHECK-DAG: [[NODE]]: DW_TAG_variable [4]
+
+define void @foo(i32 %n) !dbg !7 {
+entry:
+ call void @llvm.dbg.value(metadata i32 %n, i64 0, metadata !12, metadata !19), !dbg !20
+ ret void, !dbg !21
+}
+
+declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 5.0.1", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!1 = !DIFile(filename: "vla.c", directory: "/path/to")
+!2 = !{}
+!3 = !{i32 2, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{!"clang version 5.0.1"}
+!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 20, type: !8, isLocal: false, isDefinition: true, scopeLine: 20, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !11)
+!8 = !DISubroutineType(types: !9)
+!9 = !{null, !10}
+!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!11 = !{!12, !13, !15}
+!12 = !DILocalVariable(name: "n", arg: 1, scope: !7, file: !1, line: 20, type: !10)
+!13 = !DILocalVariable(name: "vla_expr", scope: !7, file: !1, line: 21, type: !14)
+!14 = !DIBasicType(name: "long unsigned int", size: 64, encoding: DW_ATE_unsigned)
+!15 = !DILocalVariable(name: "vla", scope: !7, file: !1, line: 21, type: !16)
+!16 = !DICompositeType(tag: DW_TAG_array_type, baseType: !10, align: 32, elements: !17)
+!17 = !{!18, !18}
+!18 = !DISubrange(count: !13)
+!19 = !DIExpression()
+!20 = !DILocation(line: 20, column: 14, scope: !7)
+!21 = !DILocation(line: 22, column: 1, scope: !7)
Index: lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1311,7 +1311,15 @@
if (DefaultLowerBound == -1 || LowerBound != DefaultLowerBound)
addUInt(DW_Subrange, dwarf::DW_AT_lower_bound, None, LowerBound);
- if (Count != -1)
+ if (auto *CV = SR->getCountVariable()) {
+ // I think we can assert() here that the DIE of the count variable has
+ // already been instantiated, since 'finishVariableDefinition' that
+ // creates the types for a variable is always called _after_ the DIEs
+ // for variables are created.
+ auto *CountVarDIE = getDIE(CV);
+ assert(CountVarDIE && "DIE for count is not yet instantiated");
+ addDIEEntry(DW_Subrange, dwarf::DW_AT_count, *CountVarDIE);
+ } else if (Count != -1)
// FIXME: An unbounded array should reference the expression that defines
// the array.
addUInt(DW_Subrange, dwarf::DW_AT_count, None, Count);
Index: lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -482,6 +482,7 @@
bool Abstract) {
// Define variable debug information entry.
auto VariableDie = DIE::get(DIEValueAllocator, DV.getTag());
+ insertDIE(DV.getVariable(), VariableDie);
if (Abstract) {
applyVariableAttributes(DV, *VariableDie);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41696.128506.patch
Type: text/x-patch
Size: 3622 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180103/04ea92a6/attachment.bin>
More information about the llvm-commits
mailing list