]> granicus.if.org Git - clang/commitdiff
Add 'DeclStmt::DoDestroy()' which doesn't actually recurse over its child expressions...
authorTed Kremenek <kremenek@apple.com>
Wed, 23 Dec 2009 08:56:00 +0000 (08:56 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 23 Dec 2009 08:56:00 +0000 (08:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91990 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Stmt.h
lib/AST/DeclGroup.cpp
lib/AST/Stmt.cpp
test/Index/c-index-crasher-rdar_7487294.c [new file with mode: 0644]

index 30a4cf7f580a40b5ecaad479f3809d391f5596e9..b58f30e319bf95b3bade07066bbf1f5fcc7c81bc 100644 (file)
@@ -294,6 +294,9 @@ class DeclStmt : public Stmt {
   DeclGroupRef DG;
   SourceLocation StartLoc, EndLoc;
 
+protected:
+  virtual void DoDestroy(ASTContext &Ctx);
+
 public:
   DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
            SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
index 5bdc8817346134db13ce6b2959a049c4940fe657..434bf00d354e346aa56beb16d037c69927222840 100644 (file)
@@ -32,6 +32,7 @@ DeclGroup::DeclGroup(unsigned numdecls, Decl** decls) : NumDecls(numdecls) {
 }
 
 void DeclGroup::Destroy(ASTContext& C) {
+  // Decls are destroyed by the DeclContext.
   this->~DeclGroup();
   C.Deallocate((void*) this);
 }
index fad80ec0cf23de5d7a74e6d7731cdf6e6ee6b629..14f0c8d744d03b177dea60597c67b60a9fbdcd65 100644 (file)
@@ -426,6 +426,14 @@ Stmt::child_iterator DeclStmt::child_end() {
   return StmtIterator(DG.end(), DG.end());
 }
 
+void DeclStmt::DoDestroy(ASTContext &C) {
+  // Don't use StmtIterator to iterate over the Decls, as that can recurse
+  // into VLA size expressions (which are owned by the VLA).  Further, Decls
+  // are owned by the DeclContext, and will be destroyed with them.
+  if (DG.isDeclGroup())
+    DG.getDeclGroup().Destroy(C);
+}
+
 // NullStmt
 Stmt::child_iterator NullStmt::child_begin() { return child_iterator(); }
 Stmt::child_iterator NullStmt::child_end() { return child_iterator(); }
diff --git a/test/Index/c-index-crasher-rdar_7487294.c b/test/Index/c-index-crasher-rdar_7487294.c
new file mode 100644 (file)
index 0000000..b01b942
--- /dev/null
@@ -0,0 +1,13 @@
+// RUN: c-index-test -test-load-source local %s 2>&1 | FileCheck %s
+
+// This is invalid source.  Previously a double-free caused this
+// example to crash c-index-test.
+
+int foo(int x) {
+  int y[x * 3];
+  help
+};
+
+// CHECK: 8:3: error: use of undeclared identifier 'help'
+// CHECK:  help
+// CHECK: 12:102: error: expected '}'