]> granicus.if.org Git - clang/commit
[analyzer] Correctly handle destructors for lifetime-extended temporaries.
authorJordan Rose <jordan_rose@apple.com>
Wed, 3 Apr 2013 21:16:58 +0000 (21:16 +0000)
committerJordan Rose <jordan_rose@apple.com>
Wed, 3 Apr 2013 21:16:58 +0000 (21:16 +0000)
commit08291a937a149dbd036fd6ac8ab061eb8034343d
tree2f833ab7f500d4b7a3627ed59a983b699d3999eb
parent88530f880e7f3b1874f6bb98d7cfe84348ed0227
[analyzer] Correctly handle destructors for lifetime-extended temporaries.

The lifetime of a temporary can be extended when it is immediately bound
to a local reference:

  const Value &MyVal = Value("temporary");

In this case, the temporary object's lifetime is extended for the entire
scope of the reference; at the end of the scope it is destroyed.

The analyzer was modeling this improperly in two ways:
- Since we don't model temporary constructors just yet, we create a fake
  temporary region when it comes time to "materialize" a temporary into
  a real object (lvalue). This wasn't taking base casts into account when
  the bindings being materialized was Unknown; now it always respects base
  casts except when the temporary region is itself a pointer.
- When actually destroying the region, the analyzer did not actually load
  from the reference variable -- it was basically destroying the reference
  instead of its referent. Now it does do the load.

This will be more useful whenever we finally start modeling temporaries,
or at least those that get bound to local reference variables.

<rdar://problem/13552274>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178697 91177308-0d34-0410-b5e6-96231b3b80d8
lib/StaticAnalyzer/Core/ExprEngine.cpp
test/Analysis/dtor.cpp