[cfe-commits] r51297 - in /cfe/trunk: include/clang/AST/Decl.h lib/AST/Decl.cpp
Ted Kremenek
kremenek at apple.com
Mon May 19 20:56:00 PDT 2008
Author: kremenek
Date: Mon May 19 22:56:00 2008
New Revision: 51297
URL: http://llvm.org/viewvc/llvm-project?rev=51297&view=rev
Log:
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).
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/lib/AST/Decl.cpp
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=51297&r1=51296&r2=51297&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon May 19 22:56:00 2008
@@ -446,10 +446,25 @@
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 {
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=51297&r1=51296&r2=51297&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Mon May 19 22:56:00 2008
@@ -412,7 +412,12 @@
}
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);
}
More information about the cfe-commits
mailing list