Do not add implicit dtors for CXXBindTemporaryExpr with elidable

CXXConstructExpr.

llvm-svn: 118991
This commit is contained in:
Zhongxing Xu 2010-11-13 07:30:59 +00:00
parent bc8b378848
commit 1b038fa00f
2 changed files with 11 additions and 13 deletions

View File

@ -2579,11 +2579,18 @@ CFGBlock *CFGBuilder::VisitBinaryOperatorForTemporaryDtors(BinaryOperator *E) {
return RHSBlock ? RHSBlock : LHSBlock;
}
static bool hasElidableCXXConstructExpr(CXXBindTemporaryExpr *E) {
if (CXXConstructExpr *CE = dyn_cast<CXXConstructExpr>(E->getSubExpr()))
if (CE->isElidable())
return true;
return false;
}
CFGBlock *CFGBuilder::VisitCXXBindTemporaryExprForTemporaryDtors(
CXXBindTemporaryExpr *E, bool BindToTemporary) {
// First add destructors for temporaries in subexpression.
CFGBlock *B = VisitForTemporaryDtors(E->getSubExpr());
if (!BindToTemporary) {
if (!BindToTemporary && !hasElidableCXXConstructExpr(E)) {
// If lifetime of temporary is not prolonged (by assigning to constant
// reference) add destructor for it.
autoCreateBlock();

View File

@ -264,14 +264,11 @@ TestCtorInits::TestCtorInits()
// CHECK: Successors (2): B3 B2
// CHECK: [ B5 ]
// CHECK: 1: ~A() (Temporary object destructor)
// CHECK: 2: ~A() (Temporary object destructor)
// CHECK: Predecessors (1): B7
// CHECK: Successors (1): B4
// CHECK: [ B6 ]
// CHECK: 1: ~A() (Temporary object destructor)
// CHECK: 2: ~A() (Temporary object destructor)
// CHECK: 3: ~A() (Temporary object destructor)
// CHECK: 4: ~B() (Temporary object destructor)
// CHECK: 2: ~B() (Temporary object destructor)
// CHECK: Predecessors (1): B7
// CHECK: Successors (1): B4
// CHECK: [ B7 ]
@ -311,14 +308,11 @@ TestCtorInits::TestCtorInits()
// CHECK: Successors (1): B0
// CHECK: [ B2 ]
// CHECK: 1: ~A() (Temporary object destructor)
// CHECK: 2: ~A() (Temporary object destructor)
// CHECK: Predecessors (1): B4
// CHECK: Successors (1): B1
// CHECK: [ B3 ]
// CHECK: 1: ~A() (Temporary object destructor)
// CHECK: 2: ~A() (Temporary object destructor)
// CHECK: 3: ~A() (Temporary object destructor)
// CHECK: 4: ~B() (Temporary object destructor)
// CHECK: 2: ~B() (Temporary object destructor)
// CHECK: Predecessors (1): B4
// CHECK: Successors (1): B1
// CHECK: [ B4 ]
@ -351,8 +345,7 @@ TestCtorInits::TestCtorInits()
// CHECK: Successors (1): B7
// CHECK: [ B9 ]
// CHECK: 1: ~A() (Temporary object destructor)
// CHECK: 2: ~A() (Temporary object destructor)
// CHECK: 3: ~B() (Temporary object destructor)
// CHECK: 2: ~B() (Temporary object destructor)
// CHECK: Predecessors (1): B10
// CHECK: Successors (1): B7
// CHECK: [ B10 ]
@ -392,7 +385,6 @@ TestCtorInits::TestCtorInits()
// CHECK: Successors (1): B0
// CHECK: [ B2 ]
// CHECK: 1: ~A() (Temporary object destructor)
// CHECK: 2: ~A() (Temporary object destructor)
// CHECK: Predecessors (1): B3
// CHECK: Successors (1): B1
// CHECK: [ B3 ]
@ -426,7 +418,6 @@ TestCtorInits::TestCtorInits()
// CHECK: Successors (1): B0
// CHECK: [ B2 ]
// CHECK: 1: ~A() (Temporary object destructor)
// CHECK: 2: ~A() (Temporary object destructor)
// CHECK: Predecessors (1): B3
// CHECK: Successors (1): B1
// CHECK: [ B3 ]