This is an archive of the discontinued LLVM Phabricator instance.

[Polly][SI] Fix a potential use-after-free
ClosedPublic

Authored by philip.pfaffe on Nov 13 2017, 1:46 PM.

Details

Summary

There is a potential use-after-free bug in Scop::buildSchedule(Region *,
LoopStackTy &, LoopInfo &). Before, we took a reference to LoopStack.back()
which is a use after free, since back is popped off further below. This didn't
crash before by pure chance, since LoopStack is actually a vector, and the
memory isn't freed upon pop. I turned this into an iterator-based algorithm.

Event Timeline

philip.pfaffe created this revision.Nov 13 2017, 1:46 PM
Meinersbur accepted this revision.Nov 14 2017, 6:34 AM

LGMT, thanks.

lib/Analysis/ScopInfo.cpp
4843

Could you consider adding an assertion LoopData != LoopStack.rend() as well?

4861

[Nit] LoopStack.size() returns size_t, no "almost-always-auto" as of LLVM coding standards.

4880

Could you consider adding a comment on why the stack has to be popped only at the end?

This revision is now accepted and ready to land.Nov 14 2017, 6:34 AM

Address Review Comments

This revision was automatically updated to reflect the committed changes.