When destroying a translation unit, deallocate its owned declarations in reverse order, because there may be dependencies among the declarations.

llvm-svn: 58244
This commit is contained in:
Douglas Gregor 2008-10-27 12:50:38 +00:00
parent 36d4ade4be
commit 89ebcb9d8d
3 changed files with 15 additions and 16 deletions

View File

@ -514,23 +514,10 @@ public:
typedef ParmVarDecl * const *param_const_iterator; typedef ParmVarDecl * const *param_const_iterator;
param_iterator param_begin() { return ParamInfo; } param_iterator param_begin() { return ParamInfo; }
param_iterator param_end() { param_iterator param_end() { return ParamInfo+param_size(); }
// 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_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; unsigned getNumParams() const;
const ParmVarDecl *getParamDecl(unsigned i) const { const ParmVarDecl *getParamDecl(unsigned i) const {

View File

@ -33,7 +33,9 @@ enum { BasicMetadataBlock = 1,
TranslationUnit::~TranslationUnit() { TranslationUnit::~TranslationUnit() {
if (OwnsDecls) { if (OwnsDecls) {
llvm::DenseSet<Decl*> Killed; llvm::DenseSet<Decl*> Killed;
for (iterator I=begin(), E=end(); I!=E; ++I) { for (std::vector<Decl*>::reverse_iterator I=TopLevelDecls.rbegin(),
E=TopLevelDecls.rend();
I!=E; ++I) {
if (Killed.count(*I)) continue; if (Killed.count(*I)) continue;
Killed.insert(*I); Killed.insert(*I);

View File

@ -3,3 +3,13 @@
// PR2942 // PR2942
typedef void fn(int); typedef void fn(int);
fn f; fn f;
int g(int x, int y);
int g(int x, int y = 2);
typedef int g_type(int, int);
g_type g;
int h(int x) {
return g(x);
}