[PATCH] D41418: IR: Fix BasicBlock::phis for empty blocks

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 19 15:37:46 PST 2017


arsenm created this revision.
Herald added a subscriber: wdng.

https://reviews.llvm.org/D41418

Files:
  lib/IR/BasicBlock.cpp


Index: lib/IR/BasicBlock.cpp
===================================================================
--- lib/IR/BasicBlock.cpp
+++ lib/IR/BasicBlock.cpp
@@ -264,7 +264,12 @@
 }
 
 iterator_range<BasicBlock::phi_iterator> BasicBlock::phis() {
-  return make_range<phi_iterator>(dyn_cast<PHINode>(&front()), nullptr);
+  PHINode *P = nullptr;
+  auto I = begin();
+  if (I != end())
+    P = dyn_cast<PHINode>(&*I);
+
+  return make_range<phi_iterator>(P, nullptr);
 }
 
 /// This method is used to notify a BasicBlock that the


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41418.127612.patch
Type: text/x-patch
Size: 522 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171219/e7471151/attachment.bin>


More information about the llvm-commits mailing list