Clear the SCEVExpander's insertion point after making deletions,

so that the SCEVExpander doesn't retain a dangling pointer as its
insert position. The dangling pointer in this case wasn't ever used
to insert new instructions, but it was causing trouble with
SCEVExpander's code for automatically advancing its insert position
past debug intrinsics.

This fixes use-after-free errors that valgrind noticed in
test/Transforms/IndVarSimplify/2007-06-06-DeleteDanglesPtr.ll and
test/Transforms/IndVarSimplify/exit_value_tests.ll.

llvm-svn: 99036
This commit is contained in:
Dan Gohman 2010-03-20 03:53:53 +00:00
parent b8d1fd0553
commit 1a2abe5580
2 changed files with 11 additions and 0 deletions

View File

@ -104,6 +104,13 @@ namespace llvm {
/// is useful for late optimization passes.
void disableCanonicalMode() { CanonicalMode = false; }
/// clearInsertPoint - Clear the current insertion point. This is useful
/// if the instruction that had been serving as the insertion point may
/// have been deleted.
void clearInsertPoint() {
Builder.ClearInsertionPoint();
}
private:
LLVMContext &getContext() const { return SE.getContext(); }

View File

@ -307,6 +307,10 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L,
}
}
}
// The insertion point instruction may have been deleted; clear it out
// so that the rewriter doesn't trip over it later.
Rewriter.clearInsertPoint();
}
void IndVarSimplify::RewriteNonIntegerIVs(Loop *L) {