[analyzer] Adjust the reported variable name in retain count checker
authorValeriy Savchenko <vsavchenko@apple.com>
Fri, 16 Apr 2021 18:10:05 +0000 (21:10 +0300)
committerValeriy Savchenko <vsavchenko@apple.com>
Wed, 28 Apr 2021 15:37:37 +0000 (18:37 +0300)
commit61ae2db2d7a97af5206afe609a303071711f9e6e
tree127ce1f2bcb9d45cf5eb083064f2025f30cc7e5a
parent1dad8c5036bc912078f7859d89e3ea571616fc4a
[analyzer] Adjust the reported variable name in retain count checker

When reporting leaks, we try to attach the leaking object to some
variable, so it's easier to understand.  Before the patch, we always
tried to use the first variable that stored the object in question.
This can get very confusing for the user, if that variable doesn't
contain that object at the moment of the actual leak.  In many cases,
the warning is dismissed as false positive and it is effectively a
false positive when we fail to properly explain the warning to the
user.

This patch addresses the bigest issue in cases like this.  Now we
check if the variable still contains the leaking symbolic object.
If not, we look for the last variable to actually hold it and use
that variable instead.

rdar://76645710

Differential Revision: https://reviews.llvm.org/D100839
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.h
clang/test/Analysis/Inputs/expected-plists/edges-new.mm.plist
clang/test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist
clang/test/Analysis/Inputs/expected-plists/retain-release.m.objc.plist
clang/test/Analysis/Inputs/expected-plists/retain-release.m.objcpp.plist
clang/test/Analysis/osobject-retain-release.cpp
clang/test/Analysis/retain-release-path-notes.m
clang/test/Analysis/retain-release.m