[PATCH] D100630: [Debug-Info][DBX] DW_TAG_rvalue_reference_type should not be generated when dwarf version is smaller than 4

ChenZheng via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 13 18:45:04 PDT 2021


shchenz updated this revision to Diff 345333.
shchenz added a comment.

1: add the FIXME for the duplicated tags issue


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100630/new/

https://reviews.llvm.org/D100630

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/test/DebugInfo/PowerPC/strict-dwarf-tags.ll


Index: llvm/test/DebugInfo/PowerPC/strict-dwarf-tags.ll
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/PowerPC/strict-dwarf-tags.ll
@@ -0,0 +1,67 @@
+; RUN: llc -filetype=obj -mtriple=powerpc64le-unknown-linux-gnu < %s | \
+; RUN:   llvm-dwarfdump -debug-info - | FileCheck %s
+; RUN: llc -filetype=obj -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN:   -strict-dwarf=true < %s | llvm-dwarfdump -debug-info - | \
+; RUN:   FileCheck %s -check-prefix=STRICT
+
+; If not strict DWARF mode, we expect DW_TAG_rvalue_reference_type at DWARF 3.
+; If strict DWARF mode, we expect DW_TAG_reference_type at DWARF 3 as DW_TAG_rvalue_reference_type
+; is a DWARF 4 tag.
+
+; CHECK: DW_TAG_rvalue_reference_type
+; CHECK-NEXT: DW_AT_type {{.*}} "int"
+; CHECK: DW_TAG_base_type
+; CHECK-NOT: DW_TAG
+; CHECK: DW_AT_name {{.*}}"int"
+; CHECK: DW_TAG_reference_type
+; CHECK-NEXT: DW_AT_type {{.*}} "int"
+;
+; FIXME: remove the redundant tag DW_TAG_reference_type. We only need one tag
+; DW_TAG_reference_type with base type int.
+;
+; STRICT-NOT: DW_TAG_rvalue_reference_type
+; STRICT: DW_TAG_reference_type
+; STRICT-NEXT: DW_AT_type {{.*}} "int"
+; STRICT: DW_TAG_base_type
+; STRICT-NOT: DW_TAG
+; STRICT: DW_AT_name {{.}}"int"
+; STRICT: DW_TAG_reference_type
+; STRICT-NEXT: DW_AT_type {{.*}} "int"
+
+define void @_Z2f1OiRi(i32* dereferenceable(4) %0, i32* dereferenceable(4) %1) #0 !dbg !9 {
+  %3 = alloca i32*, align 8
+  %4 = alloca i32*, align 8
+  store i32* %0, i32** %3, align 8
+  call void @llvm.dbg.declare(metadata i32** %3, metadata !15, metadata !DIExpression()), !dbg !16
+  store i32* %1, i32** %4, align 8
+  call void @llvm.dbg.declare(metadata i32** %4, metadata !17, metadata !DIExpression()), !dbg !18
+  ret void, !dbg !19
+}
+
+; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5, !6, !7}
+!llvm.ident = !{!8}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 13.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "1.cpp", directory: "./")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 3}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{i32 7, !"uwtable", i32 1}
+!7 = !{i32 7, !"frame-pointer", i32 2}
+!8 = !{!"clang version 13.0.0"}
+!9 = distinct !DISubprogram(name: "f1", linkageName: "_Z2f1OiRi", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!10 = !DISubroutineType(types: !11)
+!11 = !{null, !12, !14}
+!12 = !DIDerivedType(tag: DW_TAG_rvalue_reference_type, baseType: !13, size: 64)
+!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!14 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !13, size: 64)
+!15 = !DILocalVariable(name: "x", arg: 1, scope: !9, file: !1, line: 1, type: !12)
+!16 = !DILocation(line: 1, column: 15, scope: !9)
+!17 = !DILocalVariable(name: "y", arg: 2, scope: !9, file: !1, line: 1, type: !14)
+!18 = !DILocation(line: 1, column: 23, scope: !9)
+!19 = !DILocation(line: 2, column: 1, scope: !9)
Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -386,6 +386,22 @@
 }
 
 DIE &DwarfUnit::createAndAddDIE(dwarf::Tag Tag, DIE &Parent, const DINode *N) {
+  // For strict DWARF mode, only generate tags available to current DWARF
+  // version.
+  if (Asm->TM.Options.DebugStrictDwarf &&
+      DD->getDwarfVersion() < dwarf::TagVersion(Tag)) {
+    // See if there is any replacement for some tags.
+    // TODO: the naively replacement may introduce duplicated tags. For example,
+    // before the replacement, we have DW_TAG_rvalue_reference_type with type
+    // int and DW_TAG_reference_type with type int, after the replacement, now
+    // we have two DW_TAG_reference_type with type int. We should fix this.
+    if (Tag == dwarf::DW_TAG_rvalue_reference_type &&
+        DD->getDwarfVersion() >= 3)
+      Tag = dwarf::DW_TAG_reference_type;
+    else
+      // Assertion for other cases.
+      assert(false && "Tag is generated not following strict DWARF!");
+  }
   DIE &Die = Parent.addChild(DIE::get(DIEValueAllocator, Tag));
   if (N)
     insertDIE(N, &Die);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100630.345333.patch
Type: text/x-patch
Size: 4604 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210514/7c28d145/attachment.bin>


More information about the cfe-commits mailing list