From 3dda64ec0fad2fa60d882565d135ff598897fa9d Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Mon, 27 Oct 2008 12:50:38 +0000 Subject: [PATCH] When destroying a translation unit, deallocate its owned declarations in reverse order, because there may be dependencies among the declarations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58244 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Decl.h | 17 ++--------------- lib/AST/TranslationUnit.cpp | 4 +++- test/SemaCXX/fntype-decl.cpp | 10 ++++++++++ 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index be8d842525..e1e34f44c5 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -514,23 +514,10 @@ public: typedef ParmVarDecl * const *param_const_iterator; param_iterator param_begin() { return ParamInfo; } - 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_iterator param_end() { return ParamInfo+param_size(); } param_const_iterator param_begin() const { return ParamInfo; } - - param_const_iterator param_end() const { - return ParamInfo ? ParamInfo+param_size() : 0x0; - } + param_const_iterator param_end() const { return ParamInfo+param_size(); } unsigned getNumParams() const; const ParmVarDecl *getParamDecl(unsigned i) const { diff --git a/lib/AST/TranslationUnit.cpp b/lib/AST/TranslationUnit.cpp index 659aa064de..42b7ceae1e 100644 --- a/lib/AST/TranslationUnit.cpp +++ b/lib/AST/TranslationUnit.cpp @@ -33,7 +33,9 @@ enum { BasicMetadataBlock = 1, TranslationUnit::~TranslationUnit() { if (OwnsDecls) { llvm::DenseSet Killed; - for (iterator I=begin(), E=end(); I!=E; ++I) { + for (std::vector::reverse_iterator I=TopLevelDecls.rbegin(), + E=TopLevelDecls.rend(); + I!=E; ++I) { if (Killed.count(*I)) continue; Killed.insert(*I); diff --git a/test/SemaCXX/fntype-decl.cpp b/test/SemaCXX/fntype-decl.cpp index b54346624c..d9fb8bbb59 100644 --- a/test/SemaCXX/fntype-decl.cpp +++ b/test/SemaCXX/fntype-decl.cpp @@ -3,3 +3,13 @@ // PR2942 typedef void fn(int); 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); +} -- 2.40.0