[cfe-commits] r91990 - in /cfe/trunk: include/clang/AST/Stmt.h lib/AST/DeclGroup.cpp lib/AST/Stmt.cpp test/Index/c-index-crasher-rdar_7487294.c

Ted Kremenek kremenek at apple.com
Wed Dec 23 00:56:01 PST 2009


Author: kremenek
Date: Wed Dec 23 02:56:00 2009
New Revision: 91990

URL: http://llvm.org/viewvc/llvm-project?rev=91990&view=rev
Log:
Add 'DeclStmt::DoDestroy()' which doesn't actually recurse over its child expressions (via StmtIterator), as those expressions are owned by the Decls and Types (which are destroyed elsewhere).  This fixes a crasher reported in <rdar://problem/7487294>.

Added:
    cfe/trunk/test/Index/c-index-crasher-rdar_7487294.c
Modified:
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/lib/AST/DeclGroup.cpp
    cfe/trunk/lib/AST/Stmt.cpp

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=91990&r1=91989&r2=91990&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Wed Dec 23 02:56:00 2009
@@ -294,6 +294,9 @@
   DeclGroupRef DG;
   SourceLocation StartLoc, EndLoc;
 
+protected:
+  virtual void DoDestroy(ASTContext &Ctx);
+
 public:
   DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
            SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),

Modified: cfe/trunk/lib/AST/DeclGroup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclGroup.cpp?rev=91990&r1=91989&r2=91990&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclGroup.cpp (original)
+++ cfe/trunk/lib/AST/DeclGroup.cpp Wed Dec 23 02:56:00 2009
@@ -32,6 +32,7 @@
 }
 
 void DeclGroup::Destroy(ASTContext& C) {
+  // Decls are destroyed by the DeclContext.
   this->~DeclGroup();
   C.Deallocate((void*) this);
 }

Modified: cfe/trunk/lib/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=91990&r1=91989&r2=91990&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Wed Dec 23 02:56:00 2009
@@ -426,6 +426,14 @@
   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(); }

Added: cfe/trunk/test/Index/c-index-crasher-rdar_7487294.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/c-index-crasher-rdar_7487294.c?rev=91990&view=auto

==============================================================================
--- cfe/trunk/test/Index/c-index-crasher-rdar_7487294.c (added)
+++ cfe/trunk/test/Index/c-index-crasher-rdar_7487294.c Wed Dec 23 02:56:00 2009
@@ -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 '}'





More information about the cfe-commits mailing list