DeclGroupRef DG;
SourceLocation StartLoc, EndLoc;
+protected:
+ virtual void DoDestroy(ASTContext &Ctx);
+
public:
DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
}
void DeclGroup::Destroy(ASTContext& C) {
+ // Decls are destroyed by the DeclContext.
this->~DeclGroup();
C.Deallocate((void*) this);
}
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(); }
--- /dev/null
+// 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 '}'