llvm.org GIT mirror llvm / 81b03a3
[CodeExtractor] Fix iterator invalidation in findOrCreateBlockForHoisting. Summary: By replacing branches to CommonExitBlock, we remove the node from CommonExitBlock's predecessors, invalidating the iterator. The problem is exposed when the common exit block has multiple predecessors and needs to sink lifetime info. The modification in the test case trigger the issue. Reviewers: davidxl, davide, wmi Reviewed By: davidxl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D39112 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317084 91177308-0d34-0410-b5e6-96231b3b80d8 Florian Hahn 1 year, 10 months ago
2 changed file(s) with 8 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
306306 BasicBlock *NewExitBlock = CommonExitBlock->splitBasicBlock(
307307 CommonExitBlock->getFirstNonPHI()->getIterator());
308308
309 for (auto *Pred : predecessors(CommonExitBlock)) {
309 for (auto PI = pred_begin(CommonExitBlock), PE = pred_end(CommonExitBlock);
310 PI != PE;) {
311 BasicBlock *Pred = *PI++;
310312 if (Blocks.count(Pred))
311313 continue;
312314 Pred->getTerminator()->replaceUsesOfWith(CommonExitBlock, NewExitBlock);
None ; RUN: opt -S -partial-inliner -max-num-inline-blocks=2 -skip-partial-inlining-cost-analysis < %s | FileCheck %s
0 ; RUN: opt -S -partial-inliner -max-num-inline-blocks=3 -skip-partial-inlining-cost-analysis < %s | FileCheck %s
11 ; RUN: opt -S -passes=partial-inliner -max-num-inline-blocks=2 -skip-partial-inlining-cost-analysis < %s | FileCheck %s
22
33 %class.A = type { i32 }
1515 br i1 %tmp3, label %bb4, label %bb9
1616
1717 bb4: ; preds = %bb
18 %foo = icmp eq i32 %tmp2, 0
19 br i1 %foo, label %bb5, label %bb9
20
21 bb5: ; preds = %bb4
1822 call void @_ZN1A7memfuncEv(%class.A* nonnull %tmp)
1923 %tmp5 = getelementptr inbounds %class.A, %class.A* %tmp, i64 0, i32 0
2024 %tmp6 = load i32, i32* %tmp5, align 4, !tbaa !6