[PATCH] D109597: [DebugInfo] Fix of crash due to DwarfUnit::getOrCreateContextDIE returning NULL

Alok Kumar Sharma via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 17 01:18:14 PDT 2021


alok updated this revision to Diff 373164.
alok added a comment.

Minor testcase update.


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

https://reviews.llvm.org/D109597

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/test/DebugInfo/X86/ContextDICompileUnit.ll


Index: llvm/test/DebugInfo/X86/ContextDICompileUnit.ll
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/X86/ContextDICompileUnit.ll
@@ -0,0 +1,79 @@
+; REQUIRES: x86_64-linux
+
+; RUN: llc %s -filetype=asm -o - | FileCheck %s
+
+;; Simple check just to make sure it did not crash.
+; CHECK: .section        .debug_abbrev
+
+;; The test case is generated from below fortran sources
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; mod1.f90
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;MODULE mdl1
+;;      implicit none
+;;CONTAINS
+;;      SUBROUTINE sub1(rx)
+;;        USE mdl2
+;;        real , intent(in) :: rx
+;;        CALL sub2(rx)
+;;      END SUBROUTINE sub1
+;;END MODULE mdl1
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; mod2.f90
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;MODULE mdl2
+;;      implicit none
+;;CONTAINS
+;;  SUBROUTINE sub2(rx)
+;;      real, intent(in) :: rx
+;;      PRINT 'input rx '
+;;  END SUBROUTINE sub2
+;;END MODULE mdl2
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; main.f90
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;PROGRAM main
+;;      USE mdl1
+;;      CALL sub1(2.3)
+;;END PROGRAM main
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Below command crashes before fix
+;; flang -O0 -flto -g mod1.f90 mod2.f90 main.f90
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+; ModuleID = 'ContextDICompileUnit.f90'
+source_filename = "ContextDICompileUnit.f90"
+
+define void @mdl1_sub1_(i64* noalias %rx) local_unnamed_addr !dbg !9 {
+L.entry:
+  tail call void @mdl2_sub2_(i64* %rx), !dbg !14
+  ret void, !dbg !15
+}
+
+define void @mdl2_sub2_(i64* noalias nocapture readnone %rx) local_unnamed_addr !dbg !16 {
+L.entry:
+  ret void, !dbg !19
+}
+
+!llvm.dbg.cu = !{!0, !3}
+!llvm.module.flags = !{!5, !6, !7}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_Fortran90, file: !1, producer: " F90 Flang - 1.5 2017-05-01", isOptimized: true, flags: "'+flang -c -O3 -flto -emit-llvm mod1.f90'", runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2, nameTableKind: None)
+!1 = !DIFile(filename: "mod1.f90", directory: "/tmp")
+!2 = !{}
+!3 = distinct !DICompileUnit(language: DW_LANG_Fortran90, file: !4, producer: " F90 Flang - 1.5 2017-05-01", isOptimized: true, flags: "'+flang -c -O3 -flto -emit-llvm mod2.f90'", runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2, nameTableKind: None)
+!4 = !DIFile(filename: "mod2.f90", directory: "/tmp")
+!5 = !{i32 2, !"Dwarf Version", i32 4}
+!6 = !{i32 2, !"Debug Info Version", i32 3}
+!7 = !{i32 1, !"ThinLTO", i32 0}
+!9 = distinct !DISubprogram(name: "sub1", scope: !10, file: !1, line: 4, type: !11, scopeLine: 4, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
+!10 = !DIModule(scope: !0, name: "mdl1", isDecl: true)
+!11 = !DISubroutineType(types: !12)
+!12 = !{null, !13}
+!13 = !DIBasicType(name: "real", size: 32, align: 32, encoding: DW_ATE_float)
+!14 = !DILocation(line: 7, column: 1, scope: !9)
+!15 = !DILocation(line: 8, column: 1, scope: !9)
+!16 = distinct !DISubprogram(name: "sub2", scope: !17, file: !4, line: 4, type: !11, scopeLine: 4, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !3)
+!17 = !DIModule(scope: !3, name: "mdl2", isDecl: true)
+!18 = !DILocation(line: 6, column: 1, scope: !16)
+!19 = !DILocation(line: 7, column: 1, scope: !16)
Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -537,7 +537,7 @@
 }
 
 DIE *DwarfUnit::getOrCreateContextDIE(const DIScope *Context) {
-  if (!Context || isa<DIFile>(Context))
+  if (!Context || isa<DIFile>(Context) || isa<DICompileUnit>(Context))
     return &getUnitDie();
   if (auto *T = dyn_cast<DIType>(Context))
     return getOrCreateTypeDIE(T);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109597.373164.patch
Type: text/x-patch
Size: 3950 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210917/747bd214/attachment.bin>


More information about the llvm-commits mailing list