[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 16:03:31 PDT 2020
nickdesaulniers updated this revision to Diff 257885.
nickdesaulniers added a comment.
- prefer llvm_unreachable to assert(false), 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())
+ llvm_unreachable(
+ "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.257885.patch
Type: text/x-patch
Size: 1470 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200415/ff2906a0/attachment.bin>
More information about the llvm-commits
mailing list