[analyzer] Construct temporary objects of correct types, destroy them properly.
authorArtem Dergachev <artem.dergachev@gmail.com>
Wed, 30 Nov 2016 19:02:44 +0000 (19:02 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Wed, 30 Nov 2016 19:02:44 +0000 (19:02 +0000)
commit28ee2d1b0973df3295cd7eadb45473037e530ed9
treed5e0db825484edad850da932427927fd3fb207c5
parent387afc937544c353bd55e753a9d63acd5150b404
[analyzer] Construct temporary objects of correct types, destroy them properly.

When constructing a temporary object region, which represents the result of
MaterializeTemporaryExpr, track down the sub-expression for which the temporary
is necessary with a trick similar to the approach used in CodeGen, namely
by using Expr::skipRValueSubobjectAdjustments().

Then, create the temporary object region with type of that sub-expression.
That type would propagate further in a path-sensitive manner.

During destruction of lifetime-extened temporaries, consult the type of
the temporary object region, rather than the type of the lifetime-extending
variable, in order to call the correct destructor (fixes pr17001) and,
at least, not to crash by trying to call a destructor of a plain type
(fixes pr19539).

rdar://problem/29131302
rdar://problem/29131576

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

llvm-svn: 288263
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/test/Analysis/lifetime-extension.cpp [new file with mode: 0644]