[PATCH] D93441: [DebugInfo] Fix crash with -fdebug-info-for-profiling and split dwarf

Jordan Rupprecht via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 16 20:15:46 PST 2020


rupprecht created this revision.
rupprecht added a reviewer: dblaikie.
Herald added a subscriber: hiraditya.
rupprecht requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Compiling the following:

  struct b {
    template <typename c>
    void d(c e) { d(e); }
  };
  void f() { b a; a.d(0); }

With `clang -fsplit-dwarf-inlining -g -gsplit-dwarf -fdebug-info-for-profiling -O2` triggers assertion failures that the subprogram die should have already been created by `getOrCreateSubprogramDIE`. It appears to not be created because we skip that for split dwarf in some cases, so make sure we don't skip that when the `-fdebug-info-for-profiling` option is used.

Note: this fix only addresses one issue common to building this with either dwarf 4 or 5. There is a second crash here still present with dwarf 5.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93441

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/test/DebugInfo/X86/debug-info-for-profiling-crash.ll


Index: llvm/test/DebugInfo/X86/debug-info-for-profiling-crash.ll
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/X86/debug-info-for-profiling-crash.ll
@@ -0,0 +1,58 @@
+; RUN: llc %s -split-dwarf-file=%t.dwo -filetype=obj -o /dev/null
+
+;; IR simplified from:
+; struct b {
+;   template <typename c>
+;   void d(c e) { d(e); }
+; };
+; void f() { b a; a.d(0); }
+;
+;; Which raises assertion failures when running: clang -fsplit-dwarf-inlining -g -gsplit-dwarf -fdebug-info-for-profiling -O2
+
+; ModuleID = '/tmp/repro.cc'
+source_filename = "/tmp/repro.cc"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define dso_local void @_Z1fv() local_unnamed_addr !dbg !7 {
+entry:
+  br label %tailrecurse.i, !dbg !15
+
+tailrecurse.i:                                    ; preds = %tailrecurse.i, %entry
+  br label %tailrecurse.i, !dbg !15
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 12.0.0 (https://github.com/llvm/llvm-project.git 4c8c6368710ea58d940d7274dcc700eeb1c0a969)", isOptimized: true, runtimeVersion: 0, splitDebugFilename: "/tmp/repro.dwo", emissionKind: FullDebug, enums: !2, debugInfoForProfiling: true, nameTableKind: GNU)
+!1 = !DIFile(filename: "/tmp/repro.cc", directory: "/tmp")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{!"clang version 12.0.0 (https://github.com/llvm/llvm-project.git 4c8c6368710ea58d940d7274dcc700eeb1c0a969)"}
+!7 = distinct !DISubprogram(name: "f", linkageName: "_Z1fv", scope: !8, file: !8, line: 7, type: !9, scopeLine: 7, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
+!8 = !DIFile(filename: "/tmp/repro.cc", directory: "")
+!9 = !DISubroutineType(types: !10)
+!10 = !{null}
+!11 = !{!12}
+!12 = !DILocalVariable(name: "a", scope: !7, file: !8, line: 8, type: !13)
+!13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "b", file: !8, line: 1, size: 8, flags: DIFlagTypePassByValue, elements: !2, identifier: "_ZTS1b")
+!14 = !DILocation(line: 8, column: 5, scope: !7)
+!15 = !DILocation(line: 4, column: 5, scope: !16, inlinedAt: !28)
+!16 = distinct !DISubprogram(name: "d<int>", linkageName: "_ZN1b1dIiEEvT_", scope: !13, file: !8, line: 3, type: !17, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, templateParams: !22, declaration: !21, retainedNodes: !24)
+!17 = !DISubroutineType(types: !18)
+!18 = !{null, !19, !20}
+!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
+!20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!21 = !DISubprogram(name: "d<int>", linkageName: "_ZN1b1dIiEEvT_", scope: !13, file: !8, line: 3, type: !17, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, templateParams: !22)
+!22 = !{!23}
+!23 = !DITemplateTypeParameter(name: "c", type: !20)
+!24 = !{!25, !27}
+!25 = !DILocalVariable(name: "this", arg: 1, scope: !16, type: !26, flags: DIFlagArtificial | DIFlagObjectPointer)
+!26 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
+!27 = !DILocalVariable(name: "e", arg: 2, scope: !16, file: !8, line: 3, type: !20)
+!28 = distinct !DILocation(line: 9, column: 5, scope: !7)
+!29 = !DILocation(line: 0, scope: !16, inlinedAt: !28)
Index: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -982,7 +982,8 @@
   DIE *ContextDIE;
   DwarfCompileUnit *ContextCU = this;
 
-  if (includeMinimalInlineScopes())
+  // -fdebug-info-for-profiling requires a subprogram DIE.
+  if (includeMinimalInlineScopes() && !getCUNode()->getDebugInfoForProfiling())
     ContextDIE = &getUnitDie();
   // Some of this is duplicated from DwarfUnit::getOrCreateSubprogramDIE, with
   // the important distinction that the debug node is not associated with the


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93441.312366.patch
Type: text/x-patch
Size: 4369 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201217/de29f3c8/attachment.bin>


More information about the llvm-commits mailing list