Skip to content

Commit e8263f3

Browse files
committedAug 15, 2018
[SimplifyCFG] Remove pointer from SmallPtrSet before deletion
Summary: Previously, `eraseFromParent()` calls `delete` which invalidates the value of the pointer. Copying the value of the pointer later is undefined behavior in C++11 and implementation-defined (which may cause a segfault on implementations having strict pointer safety) in C++14. This patch removes the BasicBlock pointer from related SmallPtrSet before `delete` invalidates it in the SimplifyCFG pass. Reviewers: kuhar, dmgreen, davide, trentxintong Reviewed By: kuhar, dmgreen Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D50717 llvm-svn: 339773
1 parent 942e8ed commit e8263f3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
 

‎llvm/lib/Transforms/Utils/SimplifyCFG.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -3861,9 +3861,9 @@ bool SimplifyCFGOpt::SimplifySingleResume(ResumeInst *RI) {
38613861
}
38623862

38633863
// The landingpad is now unreachable. Zap it.
3864-
BB->eraseFromParent();
38653864
if (LoopHeaders)
38663865
LoopHeaders->erase(BB);
3866+
BB->eraseFromParent();
38673867
return true;
38683868
}
38693869

@@ -4083,9 +4083,9 @@ bool SimplifyCFGOpt::SimplifyReturn(ReturnInst *RI, IRBuilder<> &Builder) {
40834083
// If we eliminated all predecessors of the block, delete the block now.
40844084
if (pred_empty(BB)) {
40854085
// We know there are no successors, so just nuke the block.
4086-
BB->eraseFromParent();
40874086
if (LoopHeaders)
40884087
LoopHeaders->erase(BB);
4088+
BB->eraseFromParent();
40894089
}
40904090

40914091
return true;
@@ -4245,9 +4245,9 @@ bool SimplifyCFGOpt::SimplifyUnreachable(UnreachableInst *UI) {
42454245
// If this block is now dead, remove it.
42464246
if (pred_empty(BB) && BB != &BB->getParent()->getEntryBlock()) {
42474247
// We know there are no successors, so just nuke the block.
4248-
BB->eraseFromParent();
42494248
if (LoopHeaders)
42504249
LoopHeaders->erase(BB);
4250+
BB->eraseFromParent();
42514251
return true;
42524252
}
42534253

0 commit comments

Comments
 (0)
Please sign in to comment.