forked from OSchip/llvm-project
[CFG] Fix automatic destructors when a member is bound to a reference.
In code like const int &x = A().x; automatic destructor for the object A() lifetime-extended by reference 'x' was not present in the clang CFG due to ad-hoc pattern-matching in getReferenceInitTemporaryType(). Re-use skipRValueSubobjectAdjustments() again to find the lifetime-extended object in the AST and emit the correct destructor. Lifetime extension through aggregates with references still needs to be covered. Differential Revision: https://reviews.llvm.org/D44238 llvm-svn: 333941
This commit is contained in:
parent
d7eaf27654
commit
a25809fb74
|
@ -1493,19 +1493,18 @@ CFGBlock *CFGBuilder::addInitializer(CXXCtorInitializer *I) {
|
|||
|
||||
/// Retrieve the type of the temporary object whose lifetime was
|
||||
/// extended by a local reference with the given initializer.
|
||||
static QualType getReferenceInitTemporaryType(ASTContext &Context,
|
||||
const Expr *Init,
|
||||
static QualType getReferenceInitTemporaryType(const Expr *Init,
|
||||
bool *FoundMTE = nullptr) {
|
||||
while (true) {
|
||||
// Skip parentheses.
|
||||
Init = Init->IgnoreParens();
|
||||
|
||||
|
||||
// Skip through cleanups.
|
||||
if (const ExprWithCleanups *EWC = dyn_cast<ExprWithCleanups>(Init)) {
|
||||
Init = EWC->getSubExpr();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// Skip through the temporary-materialization expression.
|
||||
if (const MaterializeTemporaryExpr *MTE
|
||||
= dyn_cast<MaterializeTemporaryExpr>(Init)) {
|
||||
|
@ -1514,26 +1513,17 @@ static QualType getReferenceInitTemporaryType(ASTContext &Context,
|
|||
*FoundMTE = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip derived-to-base and no-op casts.
|
||||
if (const CastExpr *CE = dyn_cast<CastExpr>(Init)) {
|
||||
if ((CE->getCastKind() == CK_DerivedToBase ||
|
||||
CE->getCastKind() == CK_UncheckedDerivedToBase ||
|
||||
CE->getCastKind() == CK_NoOp) &&
|
||||
Init->getType()->isRecordType()) {
|
||||
Init = CE->getSubExpr();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip sub-object accesses into rvalues.
|
||||
SmallVector<const Expr *, 2> CommaLHSs;
|
||||
SmallVector<SubobjectAdjustment, 2> Adjustments;
|
||||
const Expr *SkippedInit =
|
||||
Init->skipRValueSubobjectAdjustments(CommaLHSs, Adjustments);
|
||||
if (SkippedInit != Init) {
|
||||
Init = SkippedInit;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip member accesses into rvalues.
|
||||
if (const MemberExpr *ME = dyn_cast<MemberExpr>(Init)) {
|
||||
if (!ME->isArrow() && ME->getBase()->isRValue()) {
|
||||
Init = ME->getBase();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1682,7 +1672,7 @@ void CFGBuilder::addAutomaticObjDtors(LocalScope::const_iterator B,
|
|||
// anything built thus far: control won't flow out of this block.
|
||||
QualType Ty = (*I)->getType();
|
||||
if (Ty->isReferenceType()) {
|
||||
Ty = getReferenceInitTemporaryType(*Context, (*I)->getInit());
|
||||
Ty = getReferenceInitTemporaryType((*I)->getInit());
|
||||
}
|
||||
Ty = Context->getBaseElementType(Ty);
|
||||
|
||||
|
@ -1795,7 +1785,7 @@ LocalScope* CFGBuilder::addLocalScopeForDeclStmt(DeclStmt *DS,
|
|||
bool CFGBuilder::hasTrivialDestructor(VarDecl *VD) {
|
||||
// Check for const references bound to temporary. Set type to pointee.
|
||||
QualType QT = VD->getType();
|
||||
if (QT.getTypePtr()->isReferenceType()) {
|
||||
if (QT->isReferenceType()) {
|
||||
// Attempt to determine whether this declaration lifetime-extends a
|
||||
// temporary.
|
||||
//
|
||||
|
@ -1805,12 +1795,16 @@ bool CFGBuilder::hasTrivialDestructor(VarDecl *VD) {
|
|||
// MaterializeTemporaryExpr instead.
|
||||
|
||||
const Expr *Init = VD->getInit();
|
||||
if (!Init)
|
||||
if (!Init) {
|
||||
// Probably an exception catch-by-reference variable.
|
||||
// FIXME: It doesn't really mean that the object has a trivial destructor.
|
||||
// Also are there other cases?
|
||||
return true;
|
||||
}
|
||||
|
||||
// Lifetime-extending a temporary.
|
||||
// Lifetime-extending a temporary?
|
||||
bool FoundMTE = false;
|
||||
QT = getReferenceInitTemporaryType(*Context, Init, &FoundMTE);
|
||||
QT = getReferenceInitTemporaryType(Init, &FoundMTE);
|
||||
if (!FoundMTE)
|
||||
return true;
|
||||
}
|
||||
|
@ -4596,7 +4590,7 @@ CFGImplicitDtor::getDestructorDecl(ASTContext &astContext) const {
|
|||
// temporary in an initializer expression.
|
||||
if (ty->isReferenceType()) {
|
||||
if (const Expr *Init = var->getInit()) {
|
||||
ty = getReferenceInitTemporaryType(astContext, Init);
|
||||
ty = getReferenceInitTemporaryType(Init);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5061,10 +5055,12 @@ static void print_elem(raw_ostream &OS, StmtPrinterHelper &Helper,
|
|||
const VarDecl *VD = DE->getVarDecl();
|
||||
Helper.handleDecl(VD, OS);
|
||||
|
||||
const Type* T = VD->getType().getTypePtr();
|
||||
if (const ReferenceType* RT = T->getAs<ReferenceType>())
|
||||
T = RT->getPointeeType().getTypePtr();
|
||||
T = T->getBaseElementTypeUnsafe();
|
||||
ASTContext &ACtx = VD->getASTContext();
|
||||
QualType T = VD->getType();
|
||||
if (T->isReferenceType())
|
||||
T = getReferenceInitTemporaryType(VD->getInit(), nullptr);
|
||||
if (const ArrayType *AT = ACtx.getAsArrayType(T))
|
||||
T = ACtx.getBaseElementType(AT);
|
||||
|
||||
OS << ".~" << T->getAsCXXRecordDecl()->getName().str() << "()";
|
||||
OS << " (Implicit destructor)\n";
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
// RUN: %clang_analyze_cc1 -fcxx-exceptions -fexceptions -analyzer-checker=debug.DumpCFG -analyzer-config cfg-rich-constructors=false %s > %t 2>&1
|
||||
// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,WARNINGS %s
|
||||
// RUN: %clang_analyze_cc1 -fcxx-exceptions -fexceptions -analyzer-checker=debug.DumpCFG -analyzer-config cfg-rich-constructors=true %s > %t 2>&1
|
||||
// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,ANALYZER %s
|
||||
// RUN: %clang_analyze_cc1 -std=c++98 -fcxx-exceptions -fexceptions -analyzer-checker=debug.DumpCFG -analyzer-config cfg-rich-constructors=false %s > %t 2>&1
|
||||
// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,CXX98,WARNINGS,CXX98-WARNINGS %s
|
||||
// RUN: %clang_analyze_cc1 -std=c++98 -fcxx-exceptions -fexceptions -analyzer-checker=debug.DumpCFG -analyzer-config cfg-rich-constructors=true %s > %t 2>&1
|
||||
// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,CXX98,ANALYZER,CXX98-ANALYZER %s
|
||||
// RUN: %clang_analyze_cc1 -std=c++11 -fcxx-exceptions -fexceptions -analyzer-checker=debug.DumpCFG -analyzer-config cfg-rich-constructors=false %s > %t 2>&1
|
||||
// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,CXX11,WARNINGS,CXX11-WARNINGS %s
|
||||
// RUN: %clang_analyze_cc1 -std=c++11 -fcxx-exceptions -fexceptions -analyzer-checker=debug.DumpCFG -analyzer-config cfg-rich-constructors=true %s > %t 2>&1
|
||||
// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,CXX11,ANALYZER,CXX11-ANALYZER %s
|
||||
|
||||
// This file tests how we construct two different flavors of the Clang CFG -
|
||||
// the CFG used by the Sema analysis-based warnings and the CFG used by the
|
||||
|
@ -14,6 +18,8 @@
|
|||
|
||||
class A {
|
||||
public:
|
||||
int x;
|
||||
|
||||
// CHECK: [B1 (ENTRY)]
|
||||
// CHECK-NEXT: Succs (1): B0
|
||||
// CHECK: [B0 (EXIT)]
|
||||
|
@ -67,6 +73,287 @@ void test_const_ref() {
|
|||
const A& c = A();
|
||||
}
|
||||
|
||||
// CHECK: [B2 (ENTRY)]
|
||||
// CHECK-NEXT: Succs (1): B1
|
||||
// CHECK: [B1]
|
||||
// WARNINGS-NEXT: 1: A() (CXXConstructExpr, class A)
|
||||
// CXX98-ANALYZER-NEXT: 1: A() (CXXConstructExpr, [B1.2], class A)
|
||||
// CXX11-ANALYZER-NEXT: 1: A() (CXXConstructExpr, [B1.2], [B1.3], class A)
|
||||
// CHECK-NEXT: 2: [B1.1] (BindTemporary)
|
||||
// CXX98-NEXT: 3: [B1.2].x
|
||||
// CXX98-NEXT: 4: [B1.3]
|
||||
// CXX98-NEXT: 5: const int &x = A().x;
|
||||
// CXX98-NEXT: 6: [B1.5].~A() (Implicit destructor)
|
||||
// CXX11-NEXT: 3: [B1.2]
|
||||
// CXX11-NEXT: 4: [B1.3].x
|
||||
// CXX11-NEXT: 5: [B1.4] (ImplicitCastExpr, NoOp, const int)
|
||||
// CXX11-NEXT: 6: const int &x = A().x;
|
||||
// CXX11-NEXT: 7: [B1.6].~A() (Implicit destructor)
|
||||
// CHECK-NEXT: Preds (1): B2
|
||||
// CHECK-NEXT: Succs (1): B0
|
||||
// CHECK: [B0 (EXIT)]
|
||||
// CHECK-NEXT: Preds (1): B1
|
||||
void test_const_ref_to_field() {
|
||||
const int &x = A().x;
|
||||
}
|
||||
|
||||
// CHECK: [B2 (ENTRY)]
|
||||
// CHECK-NEXT: Succs (1): B1
|
||||
// CHECK: [B1]
|
||||
// WARNINGS-NEXT: 1: A() (CXXConstructExpr, class A)
|
||||
// CXX98-ANALYZER-NEXT: 1: A() (CXXConstructExpr, [B1.2], class A)
|
||||
// CXX11-ANALYZER-NEXT: 1: A() (CXXConstructExpr, [B1.2], [B1.3], class A)
|
||||
// CHECK-NEXT: 2: [B1.1] (BindTemporary)
|
||||
// CXX98-NEXT: 3: A::x
|
||||
// CXX98-NEXT: 4: &[B1.3]
|
||||
// CXX98-NEXT: 5: [B1.2] .* [B1.4]
|
||||
// CXX98-NEXT: 6: [B1.5]
|
||||
// CXX98-NEXT: 7: const int &x = A() .* &A::x;
|
||||
// CXX98-NEXT: 8: [B1.7].~A() (Implicit destructor)
|
||||
// CXX11-NEXT: 3: [B1.2]
|
||||
// CXX11-NEXT: 4: A::x
|
||||
// CXX11-NEXT: 5: &[B1.4]
|
||||
// CXX11-NEXT: 6: [B1.3] .* [B1.5]
|
||||
// CXX11-NEXT: 7: [B1.6] (ImplicitCastExpr, NoOp, const int)
|
||||
// CXX11-NEXT: 8: const int &x = A() .* &A::x;
|
||||
// CXX11-NEXT: 9: [B1.8].~A() (Implicit destructor)
|
||||
// CHECK-NEXT: Preds (1): B2
|
||||
// CHECK-NEXT: Succs (1): B0
|
||||
// CHECK: [B0 (EXIT)]
|
||||
// CHECK-NEXT: Preds (1): B1
|
||||
void test_pointer_to_member() {
|
||||
const int &x = A().*&A::x;
|
||||
}
|
||||
|
||||
// FIXME: There should be automatic destructors at the end of scope.
|
||||
// CHECK: [B2 (ENTRY)]
|
||||
// CHECK-NEXT: Succs (1): B1
|
||||
// CHECK: [B1]
|
||||
// WARNINGS-NEXT: 1: A() (CXXConstructExpr, class A)
|
||||
// ANALYZER-NEXT: 1: A() (CXXConstructExpr, [B1.2], [B1.4], class A)
|
||||
// CHECK-NEXT: 2: [B1.1] (BindTemporary)
|
||||
// CHECK-NEXT: 3: [B1.2] (ImplicitCastExpr, NoOp, const class A)
|
||||
// CHECK-NEXT: 4: [B1.3]
|
||||
// CHECK-NEXT: 5: {[B1.4]}
|
||||
// CHECK-NEXT: 6: B b = {A()};
|
||||
// WARNINGS-NEXT: 7: A() (CXXConstructExpr, class A)
|
||||
// ANALYZER-NEXT: 7: A() (CXXConstructExpr, [B1.8], [B1.10], class A)
|
||||
// CHECK-NEXT: 8: [B1.7] (BindTemporary)
|
||||
// CHECK-NEXT: 9: [B1.8] (ImplicitCastExpr, NoOp, const class A)
|
||||
// CHECK-NEXT: 10: [B1.9]
|
||||
// CHECK-NEXT: 11: {[B1.10]}
|
||||
// WARNINGS-NEXT: 12: A() (CXXConstructExpr, class A)
|
||||
// ANALYZER-NEXT: 12: A() (CXXConstructExpr, [B1.13], [B1.15], class A)
|
||||
// CHECK-NEXT: 13: [B1.12] (BindTemporary)
|
||||
// CHECK-NEXT: 14: [B1.13] (ImplicitCastExpr, NoOp, const class A)
|
||||
// CHECK-NEXT: 15: [B1.14]
|
||||
// CHECK-NEXT: 16: {[B1.15]}
|
||||
// CHECK-NEXT: 17: {[B1.10], [B1.15]}
|
||||
// CHECK-NEXT: 18: B bb[2] = {A(), A()};
|
||||
// CHECK-NEXT: Preds (1): B2
|
||||
// CHECK-NEXT: Succs (1): B0
|
||||
// CHECK: [B0 (EXIT)]
|
||||
// CHECK-NEXT: Preds (1): B1
|
||||
void test_aggregate_lifetime_extension() {
|
||||
struct B {
|
||||
const A &x;
|
||||
};
|
||||
|
||||
B b = {A()};
|
||||
B bb[2] = {A(), A()};
|
||||
}
|
||||
|
||||
// In C++98 such class 'C' will not be an aggregate.
|
||||
#if __cplusplus >= 201103L
|
||||
// FIXME: There should be automatic destructors at the end of the scope.
|
||||
// CXX11: [B2 (ENTRY)]
|
||||
// CXX11-NEXT: Succs (1): B1
|
||||
// CXX11: [B1]
|
||||
// CXX11-WARNINGS-NEXT: 1: A() (CXXConstructExpr, class A)
|
||||
// CXX11-ANALYZER-NEXT: 1: A() (CXXConstructExpr, [B1.2], [B1.4], class A)
|
||||
// CXX11-NEXT: 2: [B1.1] (BindTemporary)
|
||||
// CXX11-NEXT: 3: [B1.2] (ImplicitCastExpr, NoOp, const class A)
|
||||
// CXX11-NEXT: 4: [B1.3]
|
||||
// CXX11-NEXT: 5: [B1.4] (CXXConstructExpr, const class A)
|
||||
// CXX11-WARNINGS-NEXT: 6: A() (CXXConstructExpr, class A)
|
||||
// CXX11-ANALYZER-NEXT: 6: A() (CXXConstructExpr, [B1.7], [B1.9], class A)
|
||||
// CXX11-NEXT: 7: [B1.6] (BindTemporary)
|
||||
// CXX11-NEXT: 8: [B1.7] (ImplicitCastExpr, NoOp, const class A)
|
||||
// CXX11-NEXT: 9: [B1.8]
|
||||
// CXX11-NEXT: 10: [B1.9] (CXXConstructExpr, const class A)
|
||||
// FIXME: Why does it look as if the initializer list consumes uncopied objects?
|
||||
// CXX11-NEXT: 11: {[B1.2], [B1.7]}
|
||||
// CXX11-NEXT: 12: [B1.11] (BindTemporary)
|
||||
// CXX11-NEXT: 13: [B1.12]
|
||||
// CXX11-NEXT: 14: {[B1.13]}
|
||||
// Double curly braces trigger regexps, escape as per FileCheck manual.
|
||||
// CXX11-NEXT: 15: C c = {{[{][{]}}A(), A(){{[}][}]}};
|
||||
// CXX11-NEXT: 16: ~A() (Temporary object destructor)
|
||||
// CXX11-NEXT: 17: ~A() (Temporary object destructor)
|
||||
// CXX11-WARNINGS-NEXT: 18: A() (CXXConstructExpr, class A)
|
||||
// CXX11-ANALYZER-NEXT: 18: A() (CXXConstructExpr, [B1.19], [B1.21], class A)
|
||||
// CXX11-NEXT: 19: [B1.18] (BindTemporary)
|
||||
// CXX11-NEXT: 20: [B1.19] (ImplicitCastExpr, NoOp, const class A)
|
||||
// CXX11-NEXT: 21: [B1.20]
|
||||
// CXX11-NEXT: 22: [B1.21] (CXXConstructExpr, const class A)
|
||||
// CXX11-WARNINGS-NEXT: 23: A() (CXXConstructExpr, class A)
|
||||
// CXX11-ANALYZER-NEXT: 23: A() (CXXConstructExpr, [B1.24], [B1.26], class A)
|
||||
// CXX11-NEXT: 24: [B1.23] (BindTemporary)
|
||||
// CXX11-NEXT: 25: [B1.24] (ImplicitCastExpr, NoOp, const class A)
|
||||
// CXX11-NEXT: 26: [B1.25]
|
||||
// CXX11-NEXT: 27: [B1.26] (CXXConstructExpr, const class A)
|
||||
// FIXME: Why does it look as if the initializer list consumes uncopied objects?
|
||||
// CXX11-NEXT: 28: {[B1.19], [B1.24]}
|
||||
// CXX11-NEXT: 29: [B1.28] (BindTemporary)
|
||||
// CXX11-NEXT: 30: [B1.29]
|
||||
// CXX11-NEXT: 31: {[B1.30]}
|
||||
// CXX11-WARNINGS-NEXT: 32: A() (CXXConstructExpr, class A)
|
||||
// CXX11-ANALYZER-NEXT: 32: A() (CXXConstructExpr, [B1.33], [B1.35], class A)
|
||||
// CXX11-NEXT: 33: [B1.32] (BindTemporary)
|
||||
// CXX11-NEXT: 34: [B1.33] (ImplicitCastExpr, NoOp, const class A)
|
||||
// CXX11-NEXT: 35: [B1.34]
|
||||
// CXX11-NEXT: 36: [B1.35] (CXXConstructExpr, const class A)
|
||||
// CXX11-WARNINGS-NEXT: 37: A() (CXXConstructExpr, class A)
|
||||
// CXX11-ANALYZER-NEXT: 37: A() (CXXConstructExpr, [B1.38], [B1.40], class A)
|
||||
// CXX11-NEXT: 38: [B1.37] (BindTemporary)
|
||||
// CXX11-NEXT: 39: [B1.38] (ImplicitCastExpr, NoOp, const class A)
|
||||
// CXX11-NEXT: 40: [B1.39]
|
||||
// CXX11-NEXT: 41: [B1.40] (CXXConstructExpr, const class A)
|
||||
// FIXME: Why does it look as if the initializer list consumes uncopied objects?
|
||||
// CXX11-NEXT: 42: {[B1.33], [B1.38]}
|
||||
// CXX11-NEXT: 43: [B1.42] (BindTemporary)
|
||||
// CXX11-NEXT: 44: [B1.43]
|
||||
// CXX11-NEXT: 45: {[B1.44]}
|
||||
// Double curly braces trigger regexps, escape as per FileCheck manual.
|
||||
// CXX11-NEXT: 46: {{[{][{]}}[B1.30]}, {[B1.44]{{[}][}]}}
|
||||
// Double curly braces trigger regexps, escape as per FileCheck manual.
|
||||
// CXX11-NEXT: 47: C cc[2] = {{[{][{][{]}}A(), A(){{[}][}]}}, {{[{][{]}}A(), A(){{[}][}][}]}};
|
||||
// CXX11-NEXT: 48: ~A() (Temporary object destructor)
|
||||
// CXX11-NEXT: 49: ~A() (Temporary object destructor)
|
||||
// CXX11-NEXT: 50: ~A() (Temporary object destructor)
|
||||
// CXX11-NEXT: 51: ~A() (Temporary object destructor)
|
||||
// CXX11-NEXT: Preds (1): B2
|
||||
// CXX11-NEXT: Succs (1): B0
|
||||
// CXX11: [B0 (EXIT)]
|
||||
// CXX11-NEXT: Preds (1): B1
|
||||
void test_aggregate_array_lifetime_extension() {
|
||||
struct C {
|
||||
const A (&z)[2];
|
||||
};
|
||||
|
||||
// Until C++17 there are elidable copies here, so there should be 9 temporary
|
||||
// destructors of A()s. There are no destructors of 'c' and 'cc' because this
|
||||
// aggregate has no destructor. Instead, arrays are lifetime-extended,
|
||||
// and copies of A()s within them need to be destroyed via automatic
|
||||
// destructors.
|
||||
C c = {{A(), A()}};
|
||||
C cc[2] = {{{A(), A()}}, {{A(), A()}}};
|
||||
}
|
||||
#endif
|
||||
|
||||
// CHECK: [B2 (ENTRY)]
|
||||
// CHECK-NEXT: Succs (1): B1
|
||||
// CHECK: [B1]
|
||||
// WARNINGS-NEXT: 1: A() (CXXConstructExpr, class A)
|
||||
// ANALYZER-NEXT: 1: A() (CXXConstructExpr, [B1.2], [B1.4], class A)
|
||||
// CHECK-NEXT: 2: [B1.1] (BindTemporary)
|
||||
// CHECK-NEXT: 3: [B1.2] (ImplicitCastExpr, NoOp, const class A)
|
||||
// CHECK-NEXT: 4: [B1.3]
|
||||
// CHECK-NEXT: 5: [B1.4] (CXXConstructExpr, class A)
|
||||
// WARNINGS-NEXT: 6: A() (CXXConstructExpr, class A)
|
||||
// ANALYZER-NEXT: 6: A() (CXXConstructExpr, [B1.7], [B1.9], class A)
|
||||
// CHECK-NEXT: 7: [B1.6] (BindTemporary)
|
||||
// CHECK-NEXT: 8: [B1.7] (ImplicitCastExpr, NoOp, const class A)
|
||||
// CHECK-NEXT: 9: [B1.8]
|
||||
// CHECK-NEXT: 10: [B1.9] (CXXConstructExpr, class A)
|
||||
// WARNINGS-NEXT: 11: A() (CXXConstructExpr, class A)
|
||||
// ANALYZER-NEXT: 11: A() (CXXConstructExpr, [B1.12], [B1.14], class A)
|
||||
// CHECK-NEXT: 12: [B1.11] (BindTemporary)
|
||||
// CHECK-NEXT: 13: [B1.12] (ImplicitCastExpr, NoOp, const class A)
|
||||
// CHECK-NEXT: 14: [B1.13]
|
||||
// CHECK-NEXT: 15: [B1.14] (CXXConstructExpr, class A)
|
||||
// FIXME: Why does it look as if the initializer list consumes uncopied objects?
|
||||
// CHECK-NEXT: 16: {[B1.7], [B1.12]}
|
||||
// FIXME: Why does it look as if the initializer list consumes uncopied objects?
|
||||
// CHECK-NEXT: 17: {[B1.2], {[B1.7], [B1.12]}}
|
||||
// CHECK-NEXT: 18: D d = {A(), {A(), A()}};
|
||||
// CHECK-NEXT: 19: ~A() (Temporary object destructor)
|
||||
// CHECK-NEXT: 20: ~A() (Temporary object destructor)
|
||||
// CHECK-NEXT: 21: ~A() (Temporary object destructor)
|
||||
// WARNINGS-NEXT: 22: A() (CXXConstructExpr, class A)
|
||||
// ANALYZER-NEXT: 22: A() (CXXConstructExpr, [B1.23], [B1.25], class A)
|
||||
// CHECK-NEXT: 23: [B1.22] (BindTemporary)
|
||||
// CHECK-NEXT: 24: [B1.23] (ImplicitCastExpr, NoOp, const class A)
|
||||
// CHECK-NEXT: 25: [B1.24]
|
||||
// CHECK-NEXT: 26: [B1.25] (CXXConstructExpr, class A)
|
||||
// WARNINGS-NEXT: 27: A() (CXXConstructExpr, class A)
|
||||
// ANALYZER-NEXT: 27: A() (CXXConstructExpr, [B1.28], [B1.30], class A)
|
||||
// CHECK-NEXT: 28: [B1.27] (BindTemporary)
|
||||
// CHECK-NEXT: 29: [B1.28] (ImplicitCastExpr, NoOp, const class A)
|
||||
// CHECK-NEXT: 30: [B1.29]
|
||||
// CHECK-NEXT: 31: [B1.30] (CXXConstructExpr, class A)
|
||||
// WARNINGS-NEXT: 32: A() (CXXConstructExpr, class A)
|
||||
// ANALYZER-NEXT: 32: A() (CXXConstructExpr, [B1.33], [B1.35], class A)
|
||||
// CHECK-NEXT: 33: [B1.32] (BindTemporary)
|
||||
// CHECK-NEXT: 34: [B1.33] (ImplicitCastExpr, NoOp, const class A)
|
||||
// CHECK-NEXT: 35: [B1.34]
|
||||
// CHECK-NEXT: 36: [B1.35] (CXXConstructExpr, class A)
|
||||
// FIXME: Why does it look as if the initializer list consumes uncopied objects?
|
||||
// CHECK-NEXT: 37: {[B1.28], [B1.33]}
|
||||
// FIXME: Why does it look as if the initializer list consumes uncopied objects?
|
||||
// CHECK-NEXT: 38: {[B1.23], {[B1.28], [B1.33]}}
|
||||
// WARNINGS-NEXT: 39: A() (CXXConstructExpr, class A)
|
||||
// ANALYZER-NEXT: 39: A() (CXXConstructExpr, [B1.40], [B1.42], class A)
|
||||
// CHECK-NEXT: 40: [B1.39] (BindTemporary)
|
||||
// CHECK-NEXT: 41: [B1.40] (ImplicitCastExpr, NoOp, const class A)
|
||||
// CHECK-NEXT: 42: [B1.41]
|
||||
// CHECK-NEXT: 43: [B1.42] (CXXConstructExpr, class A)
|
||||
// WARNINGS-NEXT: 44: A() (CXXConstructExpr, class A)
|
||||
// ANALYZER-NEXT: 44: A() (CXXConstructExpr, [B1.45], [B1.47], class A)
|
||||
// CHECK-NEXT: 45: [B1.44] (BindTemporary)
|
||||
// CHECK-NEXT: 46: [B1.45] (ImplicitCastExpr, NoOp, const class A)
|
||||
// CHECK-NEXT: 47: [B1.46]
|
||||
// CHECK-NEXT: 48: [B1.47] (CXXConstructExpr, class A)
|
||||
// WARNINGS-NEXT: 49: A() (CXXConstructExpr, class A)
|
||||
// ANALYZER-NEXT: 49: A() (CXXConstructExpr, [B1.50], [B1.52], class A)
|
||||
// CHECK-NEXT: 50: [B1.49] (BindTemporary)
|
||||
// CHECK-NEXT: 51: [B1.50] (ImplicitCastExpr, NoOp, const class A)
|
||||
// CHECK-NEXT: 52: [B1.51]
|
||||
// CHECK-NEXT: 53: [B1.52] (CXXConstructExpr, class A)
|
||||
// FIXME: Why does it look as if the initializer list consumes uncopied objects?
|
||||
// CHECK-NEXT: 54: {[B1.45], [B1.50]}
|
||||
// FIXME: Why does it look as if the initializer list consumes uncopied objects?
|
||||
// CHECK-NEXT: 55: {[B1.40], {[B1.45], [B1.50]}}
|
||||
// Double curly braces trigger regexps, escape as per FileCheck manual.
|
||||
// CHECK-NEXT: 56: {{[{][{]}}[B1.23], {[B1.28], [B1.33]{{[}][}]}}, {[B1.40], {[B1.45], [B1.50]{{[}][}][}]}}
|
||||
// Double curly braces trigger regexps, escape as per FileCheck manual.
|
||||
// CHECK-NEXT: 57: D dd[2] = {{[{][{]}}A(), {A(), A(){{[}][}]}}, {A(), {A(), A(){{[}][}][}]}};
|
||||
// CHECK-NEXT: 58: ~A() (Temporary object destructor)
|
||||
// CHECK-NEXT: 59: ~A() (Temporary object destructor)
|
||||
// CHECK-NEXT: 60: ~A() (Temporary object destructor)
|
||||
// CHECK-NEXT: 61: ~A() (Temporary object destructor)
|
||||
// CHECK-NEXT: 62: ~A() (Temporary object destructor)
|
||||
// CHECK-NEXT: 63: ~A() (Temporary object destructor)
|
||||
// CHECK-NEXT: 64: [B1.57].~D() (Implicit destructor)
|
||||
// CHECK-NEXT: 65: [B1.18].~D() (Implicit destructor)
|
||||
// CHECK-NEXT: Preds (1): B2
|
||||
// CHECK-NEXT: Succs (1): B0
|
||||
// CHECK: [B0 (EXIT)]
|
||||
// CHECK-NEXT: Preds (1): B1
|
||||
void test_aggregate_with_nontrivial_own_destructor() {
|
||||
struct D {
|
||||
A y;
|
||||
A w[2];
|
||||
};
|
||||
|
||||
// Until C++17 there are elidable copies here, so there should be 9 temporary
|
||||
// destructors of A()s. Destructors of 'd' and 'dd' should implicitly
|
||||
// take care of the copies, so there should not be automatic destructors
|
||||
// for copies of A()s.
|
||||
D d = {A(), {A(), A()}};
|
||||
D dd[2] = {{A(), {A(), A()}}, {A(), {A(), A()}}};
|
||||
}
|
||||
|
||||
// CHECK: [B2 (ENTRY)]
|
||||
// CHECK-NEXT: Succs (1): B1
|
||||
// CHECK: [B1]
|
||||
|
|
Loading…
Reference in New Issue