From: Marcin Swiderski Date: Mon, 25 Oct 2010 07:05:54 +0000 (+0000) Subject: Added generation of destructors for member constant size arrays. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8c5e5d6d8a316af5a9842169f541cac49717887d;p=clang Added generation of destructors for member constant size arrays. There's only one destructor call generated for each not empty array (at least for now this should be enough). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117252 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index 1026035b3b..f003879b7a 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -552,7 +552,15 @@ void CFGBuilder::addImplicitDtorsForDestructor(const CXXDestructorDecl *DD) { // First destroy member objects. for (CXXRecordDecl::field_iterator FI = RD->field_begin(), FE = RD->field_end(); FI != FE; ++FI) { - if (const CXXRecordDecl *CD = FI->getType()->getAsCXXRecordDecl()) + // Check for constant size array. Set type to array element type. + QualType QT = FI->getType(); + if (const ConstantArrayType *AT = Context->getAsConstantArrayType(QT)) { + if (AT->getSize() == 0) + continue; + QT = AT->getElementType(); + } + + if (const CXXRecordDecl *CD = QT->getAsCXXRecordDecl()) if (!CD->hasTrivialDestructor()) { autoCreateBlock(); appendMemberDtor(Block, *FI); @@ -2729,8 +2737,13 @@ static void print_elem(llvm::raw_ostream &OS, StmtPrinterHelper* Helper, } else if (CFGMemberDtor ME = E.getAs()) { FieldDecl *FD = ME.getFieldDecl(); + + const Type *T = FD->getType().getTypePtr(); + if (const Type *ET = T->getArrayElementTypeNoTypeQual()) + T = ET; + OS << "this->" << FD->getName(); - OS << ".~" << FD->getType()->getAsCXXRecordDecl()->getName() << "()"; + OS << ".~" << T->getAsCXXRecordDecl()->getName() << "()"; OS << " (Member object destructor)\n"; } } diff --git a/test/Analysis/dtors-in-dtor-cfg-output.cpp b/test/Analysis/dtors-in-dtor-cfg-output.cpp index 0483cacaff..cbf6481a6b 100644 --- a/test/Analysis/dtors-in-dtor-cfg-output.cpp +++ b/test/Analysis/dtors-in-dtor-cfg-output.cpp @@ -26,6 +26,15 @@ public: TestOrder::~TestOrder() {} +class TestArray { + A a[2]; + A b[0]; +public: + ~TestArray(); +}; + +TestArray::~TestArray() {} + // CHECK: [ B2 (ENTRY) ] // CHECK: Predecessors (0): // CHECK: Successors (1): B1 @@ -39,3 +48,13 @@ TestOrder::~TestOrder() {} // CHECK: [ B0 (EXIT) ] // CHECK: Predecessors (1): B1 // CHECK: Successors (0): +// CHECK: [ B2 (ENTRY) ] +// CHECK: Predecessors (0): +// CHECK: Successors (1): B1 +// CHECK: [ B1 ] +// CHECK: 1: this->a.~A() (Member object destructor) +// CHECK: Predecessors (1): B2 +// CHECK: Successors (1): B0 +// CHECK: [ B0 (EXIT) ] +// CHECK: Predecessors (1): B1 +// CHECK: Successors (0):