[PATCH] D78234: [BranchFolding] assert when removing INLINEASM_BR indirect targets

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 15 14:55:21 PDT 2020


nickdesaulniers updated this revision to Diff 257855.
nickdesaulniers marked an inline comment as done.
nickdesaulniers added a comment.

- inline comment, as per @efriedma


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78234

Files:
  llvm/lib/CodeGen/BranchFolding.cpp


Index: llvm/lib/CodeGen/BranchFolding.cpp
===================================================================
--- llvm/lib/CodeGen/BranchFolding.cpp
+++ llvm/lib/CodeGen/BranchFolding.cpp
@@ -159,6 +159,25 @@
 void BranchFolder::RemoveDeadBlock(MachineBasicBlock *MBB) {
   assert(MBB->pred_empty() && "MBB must be dead!");
   LLVM_DEBUG(dbgs() << "\nRemoving MBB: " << *MBB);
+#ifndef NDEBUG
+  if (MBB->hasAddressTaken())
+    for (const MachineBasicBlock &Pred : *MBB->getParent())
+      // Iterating Pred.terminators() may be unreliable in this case.
+      // MachineBasicBlock#getFirstTerminator() iterates backwards through the
+      // MachineBasicBlock's MachineInstrs to the first non-Terminal, then
+      // moves forward one and returns that. If a non-terminator gets inserted
+      // after the INLINEASM_BR, perhaps by accident, then
+      // MachineBasicBlock#getFirstTerminator() and
+      // MachineBasicBlock#terminators() will not return the INLINEASM_BR
+      // terminator.
+      for (const MachineInstr &I : Pred)
+        if (I.getOpcode() == TargetOpcode::INLINEASM_BR)
+          for (const MachineOperand &Op : I.operands())
+            if (Op.isBlockAddress() &&
+                Op.getBlockAddress()->getBasicBlock() == MBB->getBasicBlock())
+              assert(false &&
+                     "Removing MBB that's an indirect target of INLINEASM_BR");
+#endif
 
   MachineFunction *MF = MBB->getParent();
   // drop all successors.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78234.257855.patch
Type: text/x-patch
Size: 1471 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200415/35311182/attachment.bin>


More information about the llvm-commits mailing list