]> granicus.if.org Git - clang/commit
[analyzer] DeadStoresChecker: Treat locals captured by reference in C++ lambdas as...
authorDevin Coughlin <dcoughlin@apple.com>
Fri, 20 Nov 2015 01:53:44 +0000 (01:53 +0000)
committerDevin Coughlin <dcoughlin@apple.com>
Fri, 20 Nov 2015 01:53:44 +0000 (01:53 +0000)
commit4df7572a49e7cfe16328060c827c8501c3a52700
treebd9796fd632d24ed318b2eb7e23d35620f0f710c
parent8c275d55c7d2208defc9c331d12aaca7f14c9eb9
[analyzer] DeadStoresChecker: Treat locals captured by reference in C++ lambdas as escaped.

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 commit 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.

rdar://problem/22165179

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253630 91177308-0d34-0410-b5e6-96231b3b80d8
lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
test/Analysis/lambdas.cpp