This is an archive of the discontinued LLVM Phabricator instance.

[asan] Do not remove empty lifetime.start/lifetime.end ranges
ClosedPublic

Authored by vitalybuka on Jul 26 2016, 6:56 PM.

Details

Summary

Asan stack-use-after-scope check should poison alloca even if there is
no access between start and end.

This is possible for code like this:
for (int i = 0; i < 3; i++) {

int x;
p = &x;

}

"Loop Invariant Code Motion" will move "p = &x;" out of the loop, making
start/end range empty.

PR27453

Diff Detail

Repository
rL LLVM

Event Timeline

vitalybuka updated this revision to Diff 65645.Jul 26 2016, 6:56 PM
vitalybuka retitled this revision from to Do not remove empty lifetime.start/lifetime.end ranges.
vitalybuka updated this object.
vitalybuka added a reviewer: eugenis.
eugenis set the repository for this revision to rL LLVM.
eugenis added a subscriber: llvm-commits.
eugenis added inline comments.
lib/Transforms/InstCombine/InstCombineCalls.cpp
2246 ↗(On Diff #65645)

code style: "F"

vitalybuka marked an inline comment as done.Jul 27 2016, 11:44 AM
majnemer added inline comments.
test/Transforms/InstCombine/lifetime-asan.ll
10–11 ↗(On Diff #65783)

Instead of alloca + gep, why not just make you alloca have type i8?

27–28 ↗(On Diff #65783)

Ditto.

Simplified ll test

vitalybuka marked 2 inline comments as done.Jul 27 2016, 12:09 PM
majnemer added inline comments.Jul 27 2016, 12:26 PM
lib/Transforms/InstCombine/InstCombineCalls.cpp
2249 ↗(On Diff #65786)

Is it really possible for Func to be null?

vitalybuka added inline comments.Jul 27 2016, 2:23 PM
lib/Transforms/InstCombine/InstCombineCalls.cpp
2249 ↗(On Diff #65786)

I have no confident answer, but seems I can compile entire clang without null check.

vitalybuka updated this revision to Diff 65812.Jul 27 2016, 3:03 PM
vitalybuka marked 2 inline comments as done.

removed null check

I am satisfied with this change from a code and test point of view but have no idea if this is correct behavior for the sanitizer. Can somebody with more experience on that side of things comment?

lib/Transforms/InstCombine/InstCombineCalls.cpp
2246–2248 ↗(On Diff #65812)

I'd prefer that this check get split out from the other.

vitalybuka updated this revision to Diff 65817.Jul 27 2016, 3:23 PM

"if" split

vitalybuka marked an inline comment as done.Jul 27 2016, 3:23 PM
eugenis accepted this revision.Jul 27 2016, 3:27 PM
eugenis edited edge metadata.

I think this is correct from the sanitizer standpoint. It would help asan report use-after-scope for accesses after lifetime.end.

This may have performance implications (lots of poisoning/unpoisoning of locals in tight loops), but that can be fixed on the ASan side.

This revision is now accepted and ready to land.Jul 27 2016, 3:27 PM
vitalybuka retitled this revision from Do not remove empty lifetime.start/lifetime.end ranges to [asan] Do not remove empty lifetime.start/lifetime.end ranges.Jul 27 2016, 5:13 PM
vitalybuka edited edge metadata.
This revision was automatically updated to reflect the committed changes.
vitalybuka reopened this revision.Jul 28 2016, 4:03 PM
This revision is now accepted and ready to land.Jul 28 2016, 4:03 PM
This revision was automatically updated to reflect the committed changes.