[PATCH] D132542: [InstCombine] Use dyn_cast instead of cast in visitPHINode
Liao Chunyu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 24 03:16:04 PDT 2022
liaolucy created this revision.
liaolucy added reviewers: lattner, fhahn.
Herald added a subscriber: hiraditya.
Herald added a project: All.
liaolucy requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Fix crash https://github.com/llvm/llvm-project/issues/57329
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D132542
Files:
llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
Index: llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
@@ -1505,8 +1505,8 @@
// the blocks in the same order. This will help identical PHIs be eliminated
// by other passes. Other passes shouldn't depend on this for correctness
// however.
- PHINode *FirstPN = cast<PHINode>(PN.getParent()->begin());
- if (&PN != FirstPN)
+ PHINode *FirstPN = dyn_cast<PHINode>(PN.getParent()->begin());
+ if (FirstPN && &PN != FirstPN)
for (unsigned I = 0, E = FirstPN->getNumIncomingValues(); I != E; ++I) {
BasicBlock *BBA = PN.getIncomingBlock(I);
BasicBlock *BBB = FirstPN->getIncomingBlock(I);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132542.455130.patch
Type: text/x-patch
Size: 797 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220824/45526dc1/attachment.bin>
More information about the llvm-commits
mailing list