From: Ted Kremenek Date: Tue, 20 May 2008 03:56:00 +0000 (+0000) Subject: Reclaim memory allocated for ParmVarDecl's in FunctionDecl::Destroy. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b65cf41707d190d5ce3d48b9e5bd2dc9d7b4a4c0;p=clang Reclaim memory allocated for ParmVarDecl's in FunctionDecl::Destroy. Fixed a bug in ParmVarDecl::param_end(): Handle the case where there are no ParmVarDecls for a FunctionDecl, but its function prototype has formal arguments (can happen with typedefs). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51297 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index af981d9a67..0714b120ad 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -446,10 +446,25 @@ public: unsigned param_size() const { return getNumParams(); } typedef ParmVarDecl **param_iterator; typedef ParmVarDecl * const *param_const_iterator; + param_iterator param_begin() { return ParamInfo; } - param_iterator param_end() { return ParamInfo+param_size(); } + param_iterator param_end() { + + // Special-case for handling typedefs: + // + // typedef void func_t(int x); + // func_t a; + // + // In the case of the FunctionDecl for "a", there are no ParmVarDecls. + + return ParamInfo ? ParamInfo+param_size() : 0x0; + } + param_const_iterator param_begin() const { return ParamInfo; } - param_const_iterator param_end() const { return ParamInfo+param_size(); } + + param_const_iterator param_end() const { + return ParamInfo ? ParamInfo+param_size() : 0x0; + } unsigned getNumParams() const; const ParmVarDecl *getParamDecl(unsigned i) const { diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 51040d3620..c75fb8b674 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -412,7 +412,12 @@ FunctionDecl::~FunctionDecl() { } void FunctionDecl::Destroy(ASTContext& C) { - if (Body) Body->Destroy(C); + if (Body) + Body->Destroy(C); + + for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) + (*I)->Destroy(C); + Decl::Destroy(C); }