[PATCH] D130999: Fix LDV InstrRefBasedImpl to not crash when encountering unreachable MBBs.

Adrian Prantl via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 3 13:06:42 PDT 2022


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG905f2d1ecbcb: Fix LDV InstrRefBasedImpl to not crash when encountering unreachable MBBs. (authored by aprantl).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130999

Files:
  llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
  llvm/test/DebugInfo/MIR/X86/ldv_unreachable_blocks.mir


Index: llvm/test/DebugInfo/MIR/X86/ldv_unreachable_blocks.mir
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/MIR/X86/ldv_unreachable_blocks.mir
@@ -0,0 +1,38 @@
+# RUN: llc -mtriple=x86_64-apple-macos %s -start-before=livedebugvalues -filetype=obj -o - | llvm-dwarfdump - | FileCheck %s
+# CHECK: DW_TAG_subprogram
+# Test that LiveDebugValues can handle MBBs that are not reachable in a RPOT.
+--- |
+  define hidden zeroext i1 @__foo_block_invoke(i8* nocapture noundef readonly %.block_descriptor, i64 noundef %type) !dbg !5 {
+  entry:
+    %call2.i = tail call zeroext i8 @foo_len(), !dbg !10
+    %cmp.i102.i = icmp ult i8 %call2.i, 64, !dbg !10
+    br i1 %cmp.i102.i, label %bar_length.exit105.i, label %if.else.i103.i, !dbg !10
+  if.else.i103.i:                                   ; preds = %sw.bb.i
+    br label %bar_length.exit105.i
+  bar_length.exit105.i:                        ; preds = %if.else.i103.i, %sw.bb.i
+    unreachable
+  baz_size.exit:                  ; preds = %bar_length.exit131.i, %bar_length.exit105.i, %bar_length.exit.i.baz_size.exit_crit_edge
+    unreachable
+  }
+  declare zeroext i8 @foo_len() local_unnamed_addr
+  !llvm.dbg.cu = !{!0}
+  !llvm.module.flags = !{!3, !4}
+  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6, producer: "Apple clang", isOptimized: true, flags: "-fsanitize=fuzzer-no-link,address", runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, splitDebugInlining: false, nameTableKind: None, sysroot: "/", sdk: "MacOSX.sdk")
+  !2 = !{}
+  !3 = !{i32 2, !"Debug Info Version", i32 3}
+  !4 = !{i32 1, !"LTOPostLink", i32 1}
+  !5 = distinct !DISubprogram(name: "__foo_block_invoke", linkageName: "__foo_block_invoke", scope: !6, file: !6, line: 557, type: !7, scopeLine: 557, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
+  !6 = !DIFile(filename: "t.c", directory: "")
+  !7 = !DISubroutineType(types: !2)
+  !10 = !DILocation(line: 558, column: 7, scope: !12)
+  !12 = distinct !DILexicalBlock(scope: !5, file: !6, line: 557, column: 50)
+name:            __foo_block_invoke
+body:             |
+  bb.0.entry:
+    JCC_1 %bb.1, 5, implicit $eflags, debug-location !10
+  bb.28.baz_size.exit:
+    RET64 $al, debug-location !10
+  bb.1:
+    successors: 
+  bb.25.if.else.i103.i (address-taken):
+    JMP_1 %bb.28
Index: llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
===================================================================
--- llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
+++ llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
@@ -2933,12 +2933,17 @@
   // Compute mappings of block <=> RPO order.
   ReversePostOrderTraversal<MachineFunction *> RPOT(&MF);
   unsigned int RPONumber = 0;
-  for (MachineBasicBlock *MBB : RPOT) {
+  auto processMBB = [&](MachineBasicBlock *MBB) {
     OrderToBB[RPONumber] = MBB;
     BBToOrder[MBB] = RPONumber;
     BBNumToRPO[MBB->getNumber()] = RPONumber;
     ++RPONumber;
-  }
+  };
+  for (MachineBasicBlock *MBB : RPOT)
+    processMBB(MBB);
+  for (MachineBasicBlock &MBB : MF)
+    if (BBToOrder.find(&MBB) == BBToOrder.end())
+      processMBB(&MBB);
 
   // Order value substitutions by their "source" operand pair, for quick lookup.
   llvm::sort(MF.DebugValueSubstitutions);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130999.449757.patch
Type: text/x-patch
Size: 3430 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220803/e9b9540a/attachment.bin>


More information about the llvm-commits mailing list