[PATCH] D37438: Fix segfault in FlattenCFG
Daniil Fukalov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 4 08:22:37 PDT 2017
dfukalov created this revision.
Herald added subscribers: Anastasia, rampitec.
Got segfault on dereferencing nullptr since getTerminator() returned not a BranchInst but a SwitchInst.
Was found in our OpenCL compiler with HSAIL BE, was not able to create regression test for vanilla llvm (
Fixed other similar places in the file.
https://reviews.llvm.org/D37438
Files:
lib/Transforms/Utils/FlattenCFG.cpp
Index: lib/Transforms/Utils/FlattenCFG.cpp
===================================================================
--- lib/Transforms/Utils/FlattenCFG.cpp
+++ lib/Transforms/Utils/FlattenCFG.cpp
@@ -240,6 +240,8 @@
for (;CurrBlock != FirstCondBlock;
CurrBlock = CurrBlock->getSinglePredecessor()) {
BranchInst *BI = dyn_cast<BranchInst>(CurrBlock->getTerminator());
+ if (!BI)
+ continue;
CmpInst *CI = dyn_cast<CmpInst>(BI->getCondition());
if (!CI)
continue;
@@ -267,6 +269,8 @@
// Do the transformation.
BasicBlock *CB;
BranchInst *PBI = dyn_cast<BranchInst>(FirstCondBlock->getTerminator());
+ if (!PBI)
+ return false;
bool Iteration = true;
IRBuilder<>::InsertPointGuard Guard(Builder);
Value *PC = PBI->getCondition();
@@ -435,6 +439,8 @@
FirstEntryBlock->getInstList()
.splice(FirstEntryBlock->end(), SecondEntryBlock->getInstList());
BranchInst *PBI = dyn_cast<BranchInst>(FirstEntryBlock->getTerminator());
+ if (!PBI)
+ return false;
Value *CC = PBI->getCondition();
BasicBlock *SaveInsertBB = Builder.GetInsertBlock();
BasicBlock::iterator SaveInsertPt = Builder.GetInsertPoint();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37438.113757.patch
Type: text/x-patch
Size: 1195 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170904/3807949c/attachment.bin>
More information about the llvm-commits
mailing list