Index: lib/Analysis/ScopInfo.cpp =================================================================== --- lib/Analysis/ScopInfo.cpp +++ lib/Analysis/ScopInfo.cpp @@ -2792,10 +2792,14 @@ BackedgeCondition = isl_set_copy(LatchBBDom); else { SmallVector ConditionSets; - int idx = BI->getSuccessor(0) != HeaderBB; - if (!buildConditionSets(*getStmtFor(LatchBB), TI, L, LatchBBDom, - ConditionSets)) + if (!BI || + !buildConditionSets(*getStmtFor(LatchBB), TI, L, LatchBBDom, + ConditionSets)) { + isl_map_free(NextIterationMap); + isl_set_free(UnionBackedgeCondition); return false; + } + int idx = BI->getSuccessor(0) != HeaderBB; // Free the non back edge condition set as we do not need it. isl_set_free(ConditionSets[1 - idx]);