This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] DeadStoresChecker: Treat locals captured by reference in C++ lambdas as escaped.
ClosedPublic

Authored by dcoughlin on Nov 16 2015, 4:23 PM.

Details

Summary

The analyzer currently reports dead store false positives when a local variable is captured by reference in a C++ lambda.

For example:

int local = 0; 
auto lambda = [&local]() {
  local++;
};
local = 7; // False Positive: Value stored to 'local' is never read
lambda();

In this case, the assignment setting local to 7 is not a dead store because the called lambda will later read that assigned value.

This patch silences this source of false positives by treating locals captured by reference in C++ lambdas as escaped, similarly to how the DeadStoresChecker deals with locals whose address is taken.

Diff Detail

Event Timeline

dcoughlin updated this revision to Diff 40362.Nov 16 2015, 4:23 PM
dcoughlin retitled this revision from to [analyzer] DeadStoresChecker: Treat locals captured by reference in C++ lambdas as escaped..
dcoughlin updated this object.
dcoughlin added reviewers: zaks.anna, xazax.hun.
dcoughlin added a subscriber: cfe-commits.
xazax.hun edited edge metadata.Nov 17 2015, 12:41 AM

This looks good to me, I have one question inline.

lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
425

As far as I can see ThisCaptureField is not used. Does this solution work, when there is a dead store to a class member (through captured this)?

xazax.hun accepted this revision.Nov 27 2015, 12:11 AM
xazax.hun edited edge metadata.

In the meantime I realized dead store analysis only works with local variables, so I think I answered my comment.

It was commited in r253630.

This revision is now accepted and ready to land.Nov 27 2015, 12:11 AM
xazax.hun closed this revision.Nov 27 2015, 12:11 AM