[cfe-commits] r117251 - in /cfe/trunk: lib/Analysis/CFG.cpp test/Analysis/auto-obj-dtors-cfg-output.cpp

Marcin Swiderski marcin.sfider at gmail.com
Mon Oct 25 00:00:40 PDT 2010


Author: sfider
Date: Mon Oct 25 02:00:40 2010
New Revision: 117251

URL: http://llvm.org/viewvc/llvm-project?rev=117251&view=rev
Log:
Added generation of destructors for 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/auto-obj-dtors-cfg-output.cpp

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=117251&r1=117250&r2=117251&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Mon Oct 25 02:00:40 2010
@@ -641,8 +641,14 @@
       return Scope;
   }
 
-  // Check if type is a C++ class with non-trivial destructor.
+  // Check for constant size array. Set type to array element type.
+  if (const ConstantArrayType *AT = Context->getAsConstantArrayType(QT)) {
+    if (AT->getSize() == 0)
+      return Scope;
+    QT = AT->getElementType();
+  }
 
+  // Check if type is a C++ class with non-trivial destructor.
   if (const CXXRecordDecl* CD = QT->getAsCXXRecordDecl())
     if (!CD->hasTrivialDestructor()) {
       // Add the variable to scope
@@ -2707,9 +2713,11 @@
     VarDecl* VD = DE.getVarDecl();
     Helper->handleDecl(VD, OS);
 
-    Type* T = VD->getType().getTypePtr();
+    const Type* T = VD->getType().getTypePtr();
     if (const ReferenceType* RT = T->getAs<ReferenceType>())
       T = RT->getPointeeType().getTypePtr();
+    else if (const Type *ET = T->getArrayElementTypeNoTypeQual())
+      T = ET;
 
     OS << ".~" << T->getAsCXXRecordDecl()->getName().str() << "()";
     OS << " (Implicit destructor)\n";

Modified: cfe/trunk/test/Analysis/auto-obj-dtors-cfg-output.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/auto-obj-dtors-cfg-output.cpp?rev=117251&r1=117250&r2=117251&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/auto-obj-dtors-cfg-output.cpp (original)
+++ cfe/trunk/test/Analysis/auto-obj-dtors-cfg-output.cpp Mon Oct 25 02:00:40 2010
@@ -16,6 +16,11 @@
   const A& c = A();
 }
 
+void test_array() {
+  A a[2];
+  A b[0];
+}
+
 void test_scope() {
   A a;
   { A c;
@@ -165,6 +170,18 @@
 // CHECK:     Predecessors (1): B1
 // CHECK:     Successors (0):
 // CHECK:  [ B2 (ENTRY) ]
+// CHECK:    Predecessors (0):
+// CHECK:    Successors (1): B1
+// CHECK:  [ B1 ]
+// CHECK:      1: A a[2];
+// CHECK:      2: A b[0];
+// CHECK:      3: [B1.1].~A() (Implicit destructor)
+// CHECK:    Predecessors (1): B2
+// CHECK:    Successors (1): B0
+// CHECK:  [ B0 (EXIT) ]
+// CHECK:    Predecessors (1): B1
+// CHECK:    Successors (0):
+// CHECK:  [ B2 (ENTRY) ]
 // CHECK:     Predecessors (0):
 // CHECK:     Successors (1): B1
 // CHECK:  [ B1 ]





More information about the cfe-commits mailing list