[analyzer] Improve modeling for returning an object from the top frame with RVO.
authorArtem Dergachev <artem.dergachev@gmail.com>
Wed, 19 Dec 2018 23:14:06 +0000 (23:14 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Wed, 19 Dec 2018 23:14:06 +0000 (23:14 +0000)
commit179064983aa73dd32c3004eac82af220147962e3
tree2e89ee82f7456700e921584bcfdc61fb801b9191
parent217b3b20d8d2be1781dcd8a0d058f6d111922d53
[analyzer] Improve modeling for returning an object from the top frame with RVO.

Static Analyzer processes the program function-by-function, sometimes diving
into other functions ("inlining" them). When an object is returned from an
inlined function, Return Value Optimization is modeled, and the returned object
is constructed at its return location directly.

When an object is returned from the function from which the analysis has started
(the top stack frame of the analysis), the return location is unknown. Model it
with a SymbolicRegion based on a conjured symbol that is specifically tagged for
that purpose, because this is generally the correct way to symbolicate
unknown locations in Static Analyzer.

Fixes leak false positives when an object is returned from top frame in C++17:
objects that are put into a SymbolicRegion-based memory region automatically
"escape" and no longer get reported as leaks. This only applies to C++17 return
values with destructors, because it produces a redundant CXXBindTemporaryExpr
in the call site, which confuses our liveness analysis. The actual fix
for liveness analysis is still pending, but it is no longer causing problems.

Additionally, re-enable temporary destructor tests in C++17.

Differential Revision: https://reviews.llvm.org/D55804

rdar://problem/46217550

llvm-svn: 349696
clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
clang/test/Analysis/temporaries.cpp