[cfe-commits] r117252 - in /cfe/trunk: lib/Analysis/CFG.cpp test/Analysis/dtors-in-dtor-cfg-output.cpp
Marcin Swiderski
marcin.sfider at gmail.com
Mon Oct 25 00:05:54 PDT 2010
Author: sfider
Date: Mon Oct 25 02:05:54 2010
New Revision: 117252
URL: http://llvm.org/viewvc/llvm-project?rev=117252&view=rev
Log:
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).
Modified:
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/test/Analysis/dtors-in-dtor-cfg-output.cpp
Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=117252&r1=117251&r2=117252&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Mon Oct 25 02:05:54 2010
@@ -552,7 +552,15 @@
// 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 @@
} else if (CFGMemberDtor ME = E.getAs<CFGMemberDtor>()) {
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";
}
}
Modified: cfe/trunk/test/Analysis/dtors-in-dtor-cfg-output.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dtors-in-dtor-cfg-output.cpp?rev=117252&r1=117251&r2=117252&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/dtors-in-dtor-cfg-output.cpp (original)
+++ cfe/trunk/test/Analysis/dtors-in-dtor-cfg-output.cpp Mon Oct 25 02:05:54 2010
@@ -26,6 +26,15 @@
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 @@
// 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):
More information about the cfe-commits
mailing list